Customizing Cloud Hot Folder operations may result in some processes appearing to be stuck IN_PROGRESS , even when completed. You can run a script to identify and edit these statuses, so that they can be removed.
Procedure
Address the missing AOP monitoring.
Clear the stale data, taking care not to delete data that may indicate other issues.
You can use the script below to search for records with the status IN_PROGRESS and older than a configurable number of days. The system will then update the parent records to the status SUCCESS or FAILURE , so that they are picked up by clean-up jobs. By default, child entries are not updated in order to preserve information about erroneous steps. Take careful note of the Properties you may want to change section of the script below, as this identifies places where you can customize behavior.
The script can be run using the Scripting Languages option in the SAP Commerce Cloud Administration Console . Note that you need to deactivate the rollback switch in the console to ensure that results are persisted.
Sample Code
import de.hybris.platform.cloud.commons.enums.MonitorStatus
import de.hybris.platform.cloud.commons.model.MonitorHistoryDataModel
import de.hybris.platform.cloud.commons.services.monitor.job.MonitorHistoryMaintenanceCleanupStrategy
import de.hybris.platform.cronjob.enums.*
import de.hybris.platform.processing.model.BatchModel
import de.hybris.platform.servicelayer.cronjob.PerformResult
import de.hybris.platform.servicelayer.search.*
import de.hybris.platform.servicelayer.model.*
import de.hybris.platform.core.model.user.CustomerModel;
import de.hybris.platform.cloud.commons.jalo.MonitorHistoryEntryData
import de.hybris.platform.cloud.commons.jalo.MonitorHistoryData
import de.hybris.platform.servicelayer.time.impl.DefaultTimeService
import org.assertj.core.util.Lists
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery
flexibleSearchService = spring.getBean("flexibleSearchService")
modelService = spring.getBean("modelService")
/**
* START - PROPERTIES YOU MAY WANT TO CHANGE
*/
// Modify the threshold parameter to find records older than this many days
DEFAULT_THRESHOLD = 14;
// Determine whether to update the status of the child entries of the stale IN_PROGRESS parent to success.
// By default set at false, as you may want to preserve information of which steps were erroneous
updateChildEntries = Boolean.FALSE
/**
* END - PROPERTIES YOU MAY WANT TO CHANGE
*/
// Most likely the status of stale records is 'IN_PROGRESS' - you shouldn't need to change this
STATUS = MonitorStatus.IN_PROGRESS;
// Capture the status we want to change to - in most cases this would either be 'SUCCESS' or 'FAILURE',
// Depending upon what you prefer - also shouldn't need to change this (your settings for the history clean up strategy may inform this, i.e.
// failed history records are typically persisted for longer than successful
NEW_STATUS = MonitorStatus.SUCCESS
/**
* Define global variables (non typed in groovy)
*/
TEMPLATE = "SELECT {%s} FROM {%s} WHERE {%s} < ?threshold AND {%s} = ?status";
STATUS_PARAM = "status";
THRESHOLD_PARAM = "threshold";
FlexibleSearchQuery createFetchQuery(Date thresholdDate) {
HashMap<String, Object> params = new HashMap<>();
params.put(STATUS_PARAM, STATUS);
params.put(THRESHOLD_PARAM, thresholdDate);
final String queryString = String.format(TEMPLATE,
MonitorHistoryDataModel.PK,
MonitorHistoryDataModel._TYPECODE,
MonitorHistoryDataModel.MODIFIEDTIME,
MonitorHistoryDataModel.STATUS
);
return new FlexibleSearchQuery(queryString, params);
}
/**
* Modified time is a java Date, so calculate the threshold days
* as a date from now
*
* @return Date threshold days ago as a Date
*/
Date calculateThreshold() {
final Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(System.currentTimeMillis()));
calendar.add(Calendar.DATE, -DEFAULT_THRESHOLD);
return calendar.getTime();
}
void runQuery() {
Date thresholdDate = calculateThreshold()
println sprintf("Searching for records older than date [%s] (threshold was [%s] days), with Status [%s]...........", thresholdDate.toString(), DEFAULT_THRESHOLD, STATUS)
println sprintf("Found records will be updated to Status [%s]", NEW_STATUS)
println sprintf("Child entries WILL %s be updated", updateChildEntries ? "" : "NOT")
searchResult = flexibleSearchService.search(createFetchQuery(thresholdDate)).getResult()
println "START search results....."
for (hx in searchResult) {
String hxPk = hx.getPk()
println sprintf("PK: [%s], Status: [%s], Modified time: [%s]", hxPk, hx.getStatus(), hx.getModifiedtime())
hx.setStatus(NEW_STATUS)
if (updateChildEntries) {
println "START Child Entries........"
for (childHx in hx.getEntries()) {
println sprintf("Step: %s, Status: %s", childHx.getStep(), childHx.getStatus())
childHx.setStatus(NEW_STATUS)
}
println "END Child Entries........"
}
modelService.save(hx)
println sprintf("SUCCESSFULLY updated parent record with PK [%s]", hxPk)
}
println "END search results....."
}
runQuery()