wilton.js  v202103141
 All Namespaces Functions
Functions
CronTask Namespace Reference

wilton/CronTask
Run periodic tasks in background. More...

Functions

Object CronTask (Object options, Function|Undefined callback)
 Create CronTask instance.
Undefined stop (Function|Undefined callback)
 Stop periodic execution of a background task.

Detailed Description

This module allows to run tasks in background, starting them periodically specifying startup times using Cron expression.

It uses extended version of Cron expressions with support for seconds field.

Each CronTask instance starts a background thread that is used to run specified function.

To release system resources, CronTask instance can be stopped manually using stop() method, or it will be closed during the shutdown.

Usage example:

// create instance, this starts background thread
var cron = new CronTask({
expression: "0 0 7 ? * MON-FRI",
callbackScript: {
module: "path/to/task/module",
func: "taskFunction",
args: ["foo", 42]
}
});
// task is running in background periodically now
// stop task
cron.stop();

Function Documentation

Object CronTask::CronTask ( Object  options,
Function|Undefined  callback 
)

Creates task instance and starts background thread.

Parameters
optionsObject configuration object, see possible options below
callbackFunction|Undefined callback to receive result or error
Returns
Object CronTask instance

Options

  • expression String Cron expression, see expression format
  • callbackScript Object module path and function name to run from background thread
    • module String full name of JavaScript module to load
    • func String|Undefined name of the function contained in the specified module, if function is not specified, only module will be loaded (its top-level code will be executed)
    • args Array|Undefined optional list of arguments, that will be passed to specified function
Undefined CronTask::stop ( Function|Undefined  callback)

Stops the background thread releasing system resources.

Parameters
callbackFunction|Undefined callback to receive result or error
Returns
Undefined