on ‎2019 Feb 11 10:23 AM
Hello all,
Cronjobs which runs many times a day create a huge amount of CronJobHistoryEntries. Is there a solution to clean them every day?
I tried to overwrite CleanupCronJobStrategy, but failed there.
Thanks in advance.
Cheers, Serdar
Request clarification before answering.
Thanks Markus,
I solved this now by overwriting createFetchQuery
@Override
public FlexibleSearchQuery createFetchQuery(final CronJobModel cjm)
{
final Map<String, Object> params = new HashMap<>();
final StringBuilder builder = new StringBuilder();
// @formatter:off
builder.append("SELECT {" + CronJobModel.PK + "} FROM {" + CronJobModel._TYPECODE + " AS cj} WHERE ");
builder.append(" {" + CronJobModel.PK + "} IN" +
"({{" +
"SELECT" +
" {" + CronJobHistoryModel.CRONJOB + "} " +
"FROM" +
" {" + CronJobHistoryModel._TYPECODE + "} " +
"GROUP BY" +
" {" + CronJobHistoryModel.CRONJOB + "} " +
"Having" +
" count({" + CronJobHistoryModel.CRONJOB + "}) > 1" +
"}})");
if (!excludedCronJobCodes.isEmpty())
{
builder.append(" AND {" + CronJobModel.CODE + "} NOT IN ( ?excludedCronJobCodes ) ");
params.put("excludedCronJobCodes", excludedCronJobCodes);
}
// @formatter:on
final FlexibleSearchQuery query = new FlexibleSearchQuery(builder.toString(), params);
query.setResultClassList(Arrays.asList(CronJobModel.class));
return query;
}
To get this working properly it is necessary to change the settings in the backoffice for each cronjob from AND to OR
Cheers, Serdar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Groovy script can do it, create a scripting job
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
flexibleSearchService = spring.getBean "flexibleSearchService"
modelService = spring.getBean "modelService"
int count=300
FlexibleSearchQuery query = new FlexibleSearchQuery("select {pk} from {CronJobHistory} where {creationtime} < DATE_SUB(SYSDATE(), INTERVAL 3 DAY ) ");
query.setCount(count)
cronjobhistoryentry = flexibleSearchService.search(query).getResult();
modelService.removeAll(cronjobhistoryentry);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
At the moment, you have to write your own cleanup job / cleanup strategy as described here:
https://help.hybris.com/1811/hcd/8b9ba2218669101483e7f2ca38a2de96.html
It boils down to:
craft a query to fetch all the history entries you want to delete
delete them
You can even configure a new maintenance job using the scripting engine during runtime (this is also described in the link)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.