Class: MilliCron
A simple Cron Daemon which supports a resolution of up to 10ms.
Constructors
Constructor
new MilliCron(autostart?: boolean): MilliCron;Creates a new instance of the MilliCron class.
Parameters
| Parameter | Type | Description |
|---|---|---|
autostart? | boolean | Whether to automatically start the cron daemon upon instantiation. |
Returns
MilliCron
- A new instance of the MilliCron class.
Accessors
running
Get Signature
get running(): boolean;Returns a boolean indicating whether the cron daemon is currently running.
Returns
boolean
- A boolean indicating whether the cron daemon is currently running.
Methods
$clear()
$clear(event?: string): void;Removes all listeners for the specified event or all events if no event is specified.
Parameters
| Parameter | Type | Description |
|---|---|---|
event? | string | The name of the event to remove all listeners from. |
Returns
void
See
events!EventEmitter.removeAllListeners | EventEmitter.removeAllListeners
$off()
$off(event: string, cb: EventCallback): void;Removes a previously registered callback function for the specified event.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | The name of the event to remove the callback function from. |
cb | EventCallback | The callback function to remove. |
Returns
void
See
events!EventEmitter.off | EventEmitter.off
$on()
$on(event: string, cb: EventCallback): void;Registers a callback function to be executed every time the specified event is emitted.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | The name of the event to listen for. |
cb | EventCallback | The callback function to execute when the event is emitted. |
Returns
void
See
events!EventEmitter.on | EventEmitter.on
$once()
$once(event: string, cb: EventCallback): void;Registers a callback function to be executed only once when the specified event is emitted.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | The name of the event to listen for. |
cb | EventCallback | The callback function to execute when the event is emitted. |
Returns
void
See
events!EventEmitter.once | EventEmitter.once
crontabMatchesDateTime()
crontabMatchesDateTime(crontab: string, now: DateTime): boolean;Determines whether the given crontab expression matches the given date and time.
Parameters
| Parameter | Type | Description |
|---|---|---|
crontab | string | The crontab expression to check. |
now | DateTime | The date and time to check against the crontab expression. |
Returns
boolean
- A boolean indicating whether the crontab expression matches the given date and time.
getNextRunTimeForCrontab()
getNextRunTimeForCrontab(
cronExpression: string,
now?: DateTime<boolean>,
max?: DateTime<boolean>): DateTime<boolean> | undefined;Calculate the next run time for a crontab expression. This method takes a crontab expression and calculates the next time it will match, starting from the current time or a specified now time. If no match is found within the specified time range, it returns undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
cronExpression | string | The crontab expression to parse. |
now? | DateTime<boolean> | The current date and time to use as a reference when calculating the next match time. If not provided, the current date and time will be used. |
max? | DateTime<boolean> | The maximum date and time to use as a reference when calculating the next match time. If not provided, one year from the current date and time will be used. |
Returns
DateTime<boolean> | undefined
- Returns a
DateTimeobject representing the next time the crontab expression will match, orundefinedif no match is found within the specified time range.
getNextRunTimeForParsedCrontab()
getNextRunTimeForParsedCrontab(
crontab:
| CronTabObject
| DateTime<boolean>,
now?: DateTime<boolean>,
max?: DateTime<boolean>): DateTime<boolean> | undefined;Calculate the next run time for a parsed crontab expression. This method takes a parsed crontab expression (either as a DateTime object or a CronTabObject) and calculates the next time it will match, starting from the current time or a specified now time. If no match is found within the specified time range, it returns undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
crontab | | CronTabObject | DateTime<boolean> | The parsed crontab expression as a DateTime object or a CronTabObject. |
now? | DateTime<boolean> | The current time as a DateTime object. If not provided, the current UTC time will be used. |
max? | DateTime<boolean> | The maximum time as a DateTime object. If not provided, one year from the current UTC time will be used. |
Returns
DateTime<boolean> | undefined
- Returns a
DateTimeobject representing the next time the crontab expression will match, orundefinedif no match is found within the specified time range.
getParsedCronExpression()
getParsedCronExpression(cronExpression: string, now?: DateTime<boolean>):
| CronTabObject
| DateTime<boolean>;Parses the given cron expression and returns either a DateTime object representing the next time the cron expression will match, or a CronTabObject containing the parsed cron expression.
Parameters
| Parameter | Type | Description |
|---|---|---|
cronExpression | string | The cron expression to parse. |
now? | DateTime<boolean> | The current date and time to use as a reference when calculating the next match time. If not provided, the current date and time will be used. |
Returns
| CronTabObject | DateTime<boolean>
- A
DateTimeobject representing the next time the cron expression will match, or aCronTabObjectcontaining the parsed cron expression.
Throws
- Throws an error if the cron expression is so invalid that it cannot be recognized, or if the
nowparameter is not a validDateTimeobject.
restart()
restart(): void;Function
Stops the cron daemon if it is running and then starts it again.
Returns
void
start()
start(): void;Function
Starts the cron daemon if it is not already running.
Returns
void
stop()
stop(): void;Function
Stops the cron daemon if it is running.
Returns
void
crontabMatchesDateTime()
static crontabMatchesDateTime(crontab: string, now: DateTime): boolean;Check if the crontab expression matches the current time
Parameters
| Parameter | Type | Description |
|---|---|---|
crontab | string | A crontab expression, crontab alias or unix timestamp |
now | DateTime | A DateTime object representing the current time |
Returns
boolean
If the crontab expression matches the current time
getNextRunTimeForCrontab()
static getNextRunTimeForCrontab(
cronExpression: string,
now?: DateTime<boolean>,
max?: DateTime<boolean>): DateTime<boolean> | undefined;Calculate the next run time for a crontab expression. This method takes a crontab expression and calculates the next time it will match, starting from the current time or a specified now time. If no match is found within the specified time range, it returns undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
cronExpression | string | The crontab expression to parse. |
now? | DateTime<boolean> | The current date and time to use as a reference when calculating the next match time. If not provided, the current date and time will be used. |
max? | DateTime<boolean> | The maximum date and time to use as a reference when calculating the next match time. If not provided, one year from the current date and time will be used unless the crontab expression resolves to a specific date/time, in which case it will be ignored. |
Returns
DateTime<boolean> | undefined
- Returns a
DateTimeobject representing the next time the crontab expression will match, orundefinedif no match is found within the specified time range.
getNextRunTimeForParsedCrontab()
static getNextRunTimeForParsedCrontab(
crontab:
| CronTabObject
| DateTime<boolean>,
now?: DateTime<boolean>,
max?: DateTime<boolean>): DateTime<boolean> | undefined;Calculate the next run time for a parsed crontab expression. This method takes a parsed crontab expression (either as a DateTime object or a CronTabObject) and calculates the next time it will match, starting from the current time or a specified now time. If no match is found within the specified time range, it returns undefined.
Parameters
| Parameter | Type | Description |
|---|---|---|
crontab | | CronTabObject | DateTime<boolean> | The parsed crontab expression as a DateTime object or a CronTabObject. |
now? | DateTime<boolean> | The current time as a DateTime object. If not provided, the current UTC time will be used. |
max? | DateTime<boolean> | The maximum time as a DateTime object. If not provided, one year from the current UTC time will be used unless the crontab is a DateTime object, in which case it will be ignored. |
Returns
DateTime<boolean> | undefined
- Returns a
DateTimeobject representing the next time the crontab expression will match, orundefinedif no match is found within the specified time range.
getParsedCronExpression()
static getParsedCronExpression(cronExpression: string, now?: DateTime<boolean>):
| CronTabObject
| DateTime<boolean>;Parses the given cron expression and returns either a DateTime object representing the next time the cron expression will match, or a CronTabObject containing the parsed cron expression.
Parameters
| Parameter | Type | Description |
|---|---|---|
cronExpression | string | The cron expression to parse. |
now? | DateTime<boolean> | The current date and time to use as a reference when calculating the next match time. If not provided, the current date and time will be used. |
Returns
| CronTabObject | DateTime<boolean>
- A
DateTimeobject representing the next time the cron expression will match, or aCronTabObjectcontaining the parsed cron expression.
Throws
- Throws an error if the cron expression is so invalid that it cannot be recognized, or if the
nowparameter is not a validDateTimeobject.