aptible / supercronic

Cron for containers
MIT License
1.91k stars 115 forks source link

Question: Running supercronic on multiple Instances #103

Closed Hameedimran closed 2 years ago

Hameedimran commented 2 years ago

Hello devs,

Thank you, I am unable to find any proper answers, Wondering any devs can help me to understand how can I run supercron on only one instance. I have application that running with two docker instances, Currently the execution is happening in all environments in all instances, As images is promoted to from IT to PROD. How can I configure to run only on certain environments or execution based on any environment variables.

UserNotFound commented 2 years ago

If you don't want to run supercronic (or any execuatible) at all, you could use a variable and shell conditionals (or whole scripts) like:

( [ "$RUN_CRONS" = "true" ] && supercronic crontab ) || echo "All crons skipped"

With any cron implementation, you can include similar logic in the job definition (or in a script run as a job):

@hourly [ "#RUN_PROD_JOBS" = "true" ] && python ./process_orders.py

Or, you could load a different crontab file entirely for each environment. supercronic production.crontab vs supercronic dev.crontab

All of the above suggestions should work on supercronic or any other cron implementation


On Aptible, you can use the default container environment or set your own configuration values as environment variables to help decide if/which jobs should be run.