Cron Job Events
Platform can publish events on CronJob start and CronJob end. This allows developers to implement logic based on the processing of cron jobs.
When a cron job is about to start, the BeforeCronJobStartEvent event is published. Right after a cron job has finished (regardless of the result or state - even when it crashed), the AfterCronJobFinishedEvent event is fired.
Event Attributes
-
cronJob, cronJobPK, cronJobType: represent respectively the code, the PK, and the type code of a cron job being executed
-
job, jobType: represent respectively the code, and the type code of the job the cron job belongs to
-
scheduled, scheduledByTriggerPK: represent respectively whether cron job execution was scheduled, and, if so, the PK of the trigger scheduling it
-
synchronous: in case of a cron job being explicitly performed (not scheduled) this attribute tells whether it was run synchronously within the caller's thread or not
-
result: the result (enum) a cron job ended with
-
status: the status (enum) a cron job ended with
Cluster Considerations
Note that both events are published to the local Platform instance only and aren't sent to other cluster members.
However, you can register a listener that captures these events and wraps them into your own cluster aware events so that the information arrives where you need it. This is also a good opportunity to select only those cron job events that are interesting for the specific use case.
Capturing Events
Like for all other SAP Commerce events, you must implement and register an ApplicationListener spring bean. For more information, see Registering Event Listeners.