Class MiliCron

A simple Cron Daemon which supports a resolution of up to 10ms.

Hierarchy

  • MiliCron

Constructors

  • Creates a new instance of the MiliCron class.

    Parameters

    • Optional autostart: boolean

      Whether to automatically start the cron daemon upon instantiation.

    Returns MiliCron

    • A new instance of the MiliCron class.

Accessors

  • 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

  • Removes all listeners for the specified event or all events if no event is specified.

    Parameters

    • Optional event: string

      The name of the event to remove all listeners from.

    Returns void

  • Removes a previously registered callback function for the specified event.

    Parameters

    • event: string

      The name of the event to remove the callback function from.

    • cb: EventCallback

      The callback function to remove.

    Returns void

  • Registers a callback function to be executed every time the specified event is emitted.

    Parameters

    • event: string

      The name of the event to listen for.

    • cb: EventCallback

      The callback function to execute when the event is emitted.

    Returns void

  • Registers a callback function to be executed only once when the specified event is emitted.

    Parameters

    • event: string

      The name of the event to listen for.

    • cb: EventCallback

      The callback function to execute when the event is emitted.

    Returns void

  • Determines whether the given crontab expression matches the given date and time.

    Parameters

    • 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.
  • 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

    • cronExpression: string

      The cron expression to parse.

    • Optional now: DateTime

      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

    • A DateTime object representing the next time the cron expression will match, or a CronTabObject containing the parsed cron expression.

    Throws

    • Throws an error if the cron expression is so invalid that it cannot be recognized, or if the now parameter is not a valid DateTime object.
  • Stops the cron daemon if it is running and then starts it again.

    Returns void

    Function

  • Starts the cron daemon if it is not already running.

    Returns void

    Function

  • Stops the cron daemon if it is running.

    Returns void

    Function

  • Check if the crontab expression matches the current time

    Parameters

    • 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

  • 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

    • cronExpression: string

      The cron expression to parse.

    • Optional now: DateTime

      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

    • A DateTime object representing the next time the cron expression will match, or a CronTabObject containing the parsed cron expression.

    Throws

    • Throws an error if the cron expression is so invalid that it cannot be recognized, or if the now parameter is not a valid DateTime object.