CronJob

CronJobs is the most powerful tool in any software development projects. CronJobs is used to create automated tasks responsible for execute code in specific time , regularly at a certain point of time. Basically, CronJobs are used for data backups, update catalog, import or export data file or recalculate prices etc. The key concept of CronJobs, it is to start a long or periodic process in the background and execute all regulars activity in off business hours.

For Understand concept of Cronjob, We need to know about of three types that interact with each another: Cronjob, Job, Trigger and JobPerformable :-
  • JobPerformable: It is interface that contain perform method and tightly related to the Job type. Hybris recommend Generics type when implementing JobPerformable interface and perform method.
  • AbstractJobPerformable: It provides a basic functionality for a common JobPerformable implementation like request abort handling.
  • CronJob: It containsthe configuration for a single run of a Job and other information, like session settings, for a specific execution or logging configuration.
  • Job: It describes one kind of execution logic in the system and each CronJob should reference one instance. Although the Job instance does not contain any logic.
  • ServicelayerJob: It is extends to Job class and provides the springId attribute that references a Spring bean definition of the execution logic. The Spring bean has to implement the JobPerformableinterface.
  • Trigger : It is basically used for Job schedule when Job will run. It could be either on a regular basis or only once.

Step to create CronJob :

First:- If Job needs some additional configuration parameters apart from CronJob Item Type provided, then we need to define a Custom CronJob Item Type in the *items.xml by extending the CronJob Item Type.
Second : To define the logic for a job, We will create Java class which will extends AbstractJobPerformable and implement perform method.
Third : Now we will give bean entry for our custom Java class in our custom extention(spring.xml).
Fourth : To create the Cronjob and the Trigger via impex.

Leave a comment