Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain how to Create Cron Job in Hybris

Tags:

cron

hybris

I did my research but couldn't find the authentic answer. Any inputs from hybris experts highly appreciated

like image 217
prashant kumar Avatar asked May 02 '15 02:05

prashant kumar


2 Answers

  1. Cronjob: The job to be performed. For this Create an item type extending from CronJob.
  2. Job: Where the actual cronjob logic will be written. For this Create a class extending from AbstractJobPerformable<...abovegeneratedModel> and override the perform() method. Here perform method will contain actual job logic.
  3. Define the above Job class as a bean in xxxcore-spring.xml.
  4. Go to hmc-->System-->Right click on Cronjobs and Create your new cronjob.
  5. Trigger: Holds cron expression when to fire cronjob. Add the trigger conditions through TimeSchedule tab.
  6. Click StartCronJob Now to schedule the cronjob.

You can also use impex script to create trigger as thijsraets said.

INSERT_UPDATE Trigger;cronJob(code)[unique=true];cronExpression
;myCronJob;30 23 14 2 5 ? 2015
like image 71
Manohar Ch Avatar answered Oct 02 '22 19:10

Manohar Ch


You probably want this cronJob to perform a custom action, for this you need to link up the cronJob with an actual action/task: the job itself. Create a bean that extends AbstractJobPerformable and implements the "perform" method. Now in the hMC you can create your Cron Job (System->CronJobs), under Job point to the bean you have created.

If you would like to do this from code you can use impex, for instance:

INSERT_UPDATE CronJob;code[unique=true];job(code);sessionLanguage(isocode);sessionCurrency(isocode)
;myCronJob;myJobBean;en;EUR

INSERT_UPDATE Trigger;cronJob(code)[unique=true];cronExpression
;myCronJob;30 23 14 2 5 ? 2015

Assign to a String and import this impex (or just execute in hac):

final CSVReader importReader = new CSVReader(impEx);
final Importer importer = new Importer(importReader);

importer.getReader().setDumpingAllowed(true);
try
{
    importer.importAll();
}
catch (final ImpExException e)
{
    e.printStackTrace();
}
importReader.closeQuietly();
importer.close();

(If you are using 5.5.1: the triggers do not work properly if you indicate multiple execution times. No problem if you only specify a single execution time , we hope SAP will solve this)

like image 42
thijsraets Avatar answered Oct 02 '22 18:10

thijsraets