here is the thing: I have a stack where a node js backend sends messages to a queue and perl workers (cron jobs) consume messages from that queue. I already "dockerized" the node js backend but now I'm trying to do the same with the Perl Workers.
Already dockerized the Perl application itself however, as the "jobs" from the queue are consumed based on a crontab (i.e every 2 mins) my question would be:
What's the best way to accomplish this when having a stack built from a docker-compose file?
Let me know if I should provide more details. Thanks!
How to schedule tasks in Docker. There are a couple of ways you can create scheduled tasks in Docker using cron. In this article we'll walk through using the host's crontab, using cron within your containers, and separating cron from your application's services.
What does * mean in Cron? The asterisk * is used as a wildcard in Cron. * sets the execution of a task to any minute, hour, day, weekday, or month.
Cron jobs are typically located in the spool directories. They are stored in tables called crontabs. You can find them in /var/spool/cron/crontabs. The tables contain the cron jobs for all users, except the root user.
I got it solved with the help of How to run a cron job inside a docker container? however, I had to add the line:
RUN crontab /etc/cron.d/crontab
which basically Loads the crontab data from the specified file. If i did not do it that way, the cron daemon never starts.
Hope this helps however, still not clear if this is the best way to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With