Node.js · Senior · Question 68 of 75
What is a reasonable way to run scheduled tasks (cron) in a Node.js service with several instances?
- ✓Correct answer: Use a scheduler that runs the job once (a queue's repeatable jobs, a distributed lock or the platform's cron), not a timer in every instance
- 2Run jobs only when a user makes a request
- 3Use
setIntervalin every instance
Explanation
With a timer in each of 5 instances the job runs 5 times. Jobs should still be idempotent in case a run is repeated.