'Heroku clock process already runs job when pushed to server

I'm using the Heroku clock process to schedule jobs to run. This is my procfile.

web: node index.js
worker: node worker.js
clock: node clock.js

The following is my clock.js, which should run every 30th minute of the hour.

const CronJob = require('cron').CronJob;
const worker = require('./worker');

const job = new CronJob({
    cronTime: "30 */1 * * *",
    onTick: worker.start(),
    timeZone: "Asia/Ho_Chi_Minh"
});

job.start();

My worker.js holds the code to be executed

exports.start = () => {
    // Code to be ran
};

The issue when I push changes to Heroku, the code is executed straight away by my clock dyno, and at 30 past the hour nothing is happening.

enter image description here

Any idea if I'm missing something?



Solution 1:[1]

Try removing the () at the end of worker.start. The parentheses make the function run immediately.

Solution 2:[2]

This way you are starting the worker at the same Clock's Dyno. You should use RabbitMQ or something similar

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Samantha Capps
Solution 2 Danide Rodrigues