Choose where the job lives
- Inside your existing app: simplest, if the job is light and shares code with it.
- In a separate background application: better if the job is heavy or you don’t want it to compete with requests for memory. It restarts and scales on its own.
Node.js
index.js
Python
main.py
BlockingScheduler keeps the process alive. With a script that ends after scheduling, the process
exits with code 0 and isn’t restarted.
Things to get right
Always set the timezone
Always set the timezone
Don’t depend on the container’s clock zone: pass the timezone to the scheduler explicitly, as in
the examples.
Make jobs safe to run twice
Make jobs safe to run twice
A restart during a job means it may run again. Record what was processed, or design the job so a
second run changes nothing.
Catch errors inside the job
Catch errors inside the job
An unhandled error can take the whole process down, and 5 crashes in 10 minutes pause
auto-restart for 24 hours. Wrap the job body in
try/catch and log the failure.Log every run
Log every run
Print a line when a job starts and ends; the Logs tab is where you’ll check that it ran. In Python
use
flush=True so the line appears immediately.