Friday, August 19, 2022

[FIXED] What is the best solution for Cron Schedule environmental variables in a Docker container?

Issue

I have a Python script that will run on certain intervals as the cron schedule will invoke the Python script inside a Docker container. I want the cron schedule expression to be set through an environment variable, like this:

CRON_SCHEDULE="*/5 * * * *"

So the user can freely choose how often the script will run. On the other hand, I have a hard time making a bash script that will read this environment file and replace the existing crontab using sed as I need to escape any possible character.

That brings me to the point where I'm wondering if there is any better solution for running a Python script on a schedule while also having easy configuration of the running schedule?


Solution

You should use the solution described in this answer https://stackoverflow.com/a/70897876/3669093

Whenever the environment variable is changed the container is restarted and the schedule is updated.

If you need more guidance, shoot your questions.



Answered By - mwalidawadeen
Answer Checked By - Marilyn (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.