Usage (JavaScript)
Basic usage #
Croner uses the function new Cron() which takes in three arguments:
;
If the function is omitted in the constructor, it can be scheduled later:
;
The job will be scheduled to run at the next matching time unless you supply the option { paused: true }. The Cron(...) constructor will return a Cron instance, later referred to as job, which have a few methods and properties.
Status #
Check the status of the job using the following methods:
/*optional*/ startFromDate ; // Get a Date object representing the next run.
10, /*optional*/ startFromDate ; // Get an array of Dates, containing the next n runs.
10, /*optional*/ referenceDate ; // Get an array of Dates, containing previous n scheduled runs.
/*optional*/ startFromDate ; // Get a stateful CronIterator for use in for...of / destructuring.
/*optional*/ startFromDate ; // Get the milliseconds left until the next execution.
; // Get a Date object showing when the current (or last) run was started.
; // Get a Date object showing when the previous job was started.
date ; // Check if a Date object or date string matches the cron pattern (true or false).
; // Indicates if the job is scheduled and not paused or killed (true or false).
; // Indicates if the job is permanently stopped using `stop()` (true or false).
; // Indicates if the job is currently busy doing work (true or false).
; // Returns the original cron pattern string, or undefined for date-based jobs
; // Returns the original run-once date (Date or null)
/*optional*/ language ; // Describe the pattern in words, or undefined for date-based jobs
Describing a pattern #
job.describe() returns a description of the pattern in English, such as "At 12:00, on Monday, Tuesday, Wednesday, Thursday, and Friday." for 0 12 * * MON-FRI. Pass swedish, or your own
phrases, for another language. Spread a language to change parts of it:
;
new "0 12 * * MON-FRI"swedish;
// "Klockan 12:00, på måndag, tisdag, onsdag, torsdag och fredag."
;
new "0 14 * * *"twelveHour; // "At 2:00 PM."
Control Functions #
Control the job using the following methods:
; // Force a trigger instantly
; // Pause trigger
; // Resume trigger
; // Stop the job completely. It is not possible to resume after this.
// Note that this also removes named jobs from the exported `scheduledJobs` array.
Properties #
job.name // Optional job name, populated if a name were passed to options