Swarm-cronjob brings a lot of convenience to the table. “Jobs” are configured via labels. It works well in a distributed setup and even implements basic locking mechanisms so the tasks don’t build up when one is running already.
Deploy the following to your endpoint:
A few things to note:
swarm-cronjobwill use docker APIs to look for new containers (more on this below). While convenient for this use-case, access to the Docker APIs has security implications.
- Take note of the
LOG_LEVELin case jobs don’t work as expected.
- Don’t run
To save some time, we’ve assembled the stack and a
make deploy) into a repository on Github: hostwithquantum/example-swarm-cronjob
After a successful deployment of the stack, swarm-cronjob will wait for new services and directions. No further restarts are required.
Add the following to your
The example runs the backup service/cronjob every 30 minutes.
For brevity, we omit the configuration of the
mc client, but see the official documentation for help.
The format used in cron expression in swarm-cronjob is not not the usual
crond-format you may be familiar with. Instead of minutes (on the left), this expression starts with seconds. See the documentation for details.
When multiple jobs are deployed, execution may need to be spread out:
- each job requires certain resources to start and run
- executing many of jobs in parallel can impact other services