Subscribe to our list to receive the latest updates on Node on Fire

Class: Clock


new Clock(app)

The clock module is responsible for the clock process type. The clock process schedules tasks to run at scheduled time intervals in your worker processes. The clock module is used by e.g. the Triggers and the Scheduler module. The clock module guarantees to schedule tasks without skipping an interval.

Tip: explicitly set the TZ environment to your time zone and align this with the time zone set in your datastore. This to avoid any issues with dates and their time zones.

Because the clock process might at some point restart or crash and potentially skip a scheduled task, the clock process checks at start-up, if it skipped any task based on the date of the previous executed task. If it identifies a skipped task, it'll schedule the task immediately.

For example, consider a task which sends a mail to all users every month at the 1st day of the month at 13:00 hour exactly. If the clock process crashes at 12:59 hour and starts again at 13:01 the time interval was skipped. The clock module recognizes this and schedules the task at 13:01 instead.

(When the clock module starts the first time, and there are no results, it inserts a fake clock result).

You generally do not need to manually use this Clock module. The Clock module is used by Schedulers and Triggers. If you want to run the clock process, define the below in your Procfile (this is automatically added when creating triggers or schedulers).

clock: node index.js --clock
Name Type Description
app App


addTask(timingPattern, taskName, callback)

Creates a task to run at a time interval. The callback is guaranteed to run. The callback should schedule a job on a worker process and not actually execute any work.

Please have a look at the Schedule and Trigger modules if you want to execute work on a worker process.

Name Type Description
timingPattern String

A cron-style timing pattern. For more information, see

taskName String

The name of the task to run.

callback function

The function which schedules a job on a worker process.


Stops all the tasks. This is executed when the app is killed.

Do you have any questions or comments on this page? Start a discussion below.

comments powered by Disqus
Subscribe to our list to receive the latest updates on Node on Fire