Schedule a reoccurring background job rendering specific report template
Every report rendering time plan is specified by the report template and CRON expression identifying time occurrence. To create a rendering time plan you need to create and enable Schedule
entity from the jsreport studio or API. When a Schedule
is enabled you can veriffy NextRun
property and every time rendering is done you can also download output report from the studio or API entity Task
.
Scheduling
requires and heavily relies on scripts and reports extension. Where reports are used to store rendering output and scripts are usually used to fetch input data and send the result.
Common use case for scheduling
extension can be daily sending summary report. Whereschedule
report template will define document with summary tables and charts. Script will fetch input data before rendering and afterwards sends report by mail or upload result to external service. Note the script can reach more information about the current schedule in property req.options.scheduling.schedule
.
The extension implements mechanism to support the proper function in clustered environment with multiple jsreport instances. It's guaranteed only one schedule will be triggered.
CRON expression is unix standard for specifying time occurrence. It is a string which consists from 5 or 6 segments.
Every segment identifies particular unit. In every segment you can use also wildcard *
, interval (1-5) and steps (*/5).
Some examples:
*/10 * * * * *
- run every 10 seconds00 30 11 * * 1-5
- run every weekday at 11:30:00You can find full document with specification here.
The default implementation guarantees to run the schedule even if the server is down or overloaded for a limited time. This could be undesired and you may want to configure schedules processing to skip schedules run when they are misfired for specific time. This can be done with the config misfireThreshold
. Its value represents for how many ms can be schedule overdue and still run when server gets healthy.
Add scheduling
node to the standard config file. The defaults are following.
"extensions": {
"scheduling": {
//how often in ms jsreport checks scheduled jobs
"interval": 5000,
//how many jobs can run in parallel
"maxParallelJobs": 5,
"misfireThreshold": "300000",
// by default jsreport keeps history of every schedule run
// this can have performance impact when having many schedules running often
// the following two configs can start the automatical cleanup of the history
"cleanScheduleHistoryInterval": 60000,
"maxHistoryPerSchedule": 10
}
}