Skip to content
This repository has been archived by the owner on Jan 7, 2021. It is now read-only.

enonic/app-cronjob

Repository files navigation

Simple scheduler for Enonic XP

Build Status codecov License

This application enables simple cron-scheduling of jobs via Enonic's Cron library. The jobs are implemented in pure JavaScript and bundled into your own application. It is not cluster safe since every job is executed in its own node. If you install the application that contains the jobs on every node, then every node will execute the same code.

Installing

Simply install the application from Enonic Market.

Setting up jobs

After you have installed this application you can create your first job. Create a job in your application by adding a javascript file inside /jobs folder. The job's entry point must be exported outside via run method.

myjob.js:

exports.run = function() {
    log.info('Hello Job!');
};

The job will by default run with anonymous access-rights. So if you need to run it under a different user/role, you will have to do a context-switch (see documentation of context-functions).

Next you will have to schedule the job. To schedule jobs, create a file called /jobs/jobs.xml that contains the following code:

<jobs>
  <job name="myjob" cron="* * * * *"/>
</jobs>

where myjob.js is the name of your Javascript file.

You can have multiple jobs scheduled. The name is which script to execute and cron is a cron-pattern (see UINX cron pattern).