node-cron / node-cron

A simple cron-like job scheduler for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cron runs multiple times based on number of vCPUs

ashin-kk opened this issue · comments

commented

Hi, I find a problem while using node-cron.

The cron function is called multiple times based on the number of CPUs the server is running on.

For example - if the server has 4 cores - the function is called 4 times. If there are 2 cores it will be called 2 times.

When running in a local environment, it works perfectly as only one CPU is running at a time.
Please guide how to resolve this issue. We depend heavily on corn jobs.

Regards,
Ashin

commented

Examples

4 Core CPU

image

2 Core CPU

image

Local env

image

I also had this problem but I decoupled the cron jobs into a single cpu worker. This way there are no replications

commented

@0xayot
Thanks for the response. Can you please guide me how to achieve this?

Regards,
Ashin

Screenshot 2024-06-06 at 19 15 42

This is what my worker file looks like.
I setup my build command to run the code in the file as a standalone node instance.

node src/cronworker.js