Multi-Cron runs multiple cron jobs
3.3K
Multi-Cron is a cron runner written in Go, which utilizes version 2.0 of Rob Figueirdo's open source cron Go library
It will schedule one or more cron-style jobs which run asynchronously with stdio and stderr redirected to the console.
The cron schedule format used is slicker than regular old cron in that it has a minimum resolution of 1 second, timezone support, and useful frequencies aliases.
This application is tailor-made to run as the entrypoint (PID 1) of a Docker container and run 1 or more
applications/scripts,
configured via environmental variables, but it can also run as a stand-alone executable if you want to do that for some reason.
sudo docker run -d \
-e CRON_SCH_1="!@daily" -e CRON_CMD_1="echo" CRON_ARGS_1 -e "I ran at midnight" \
-e CRON_SCH_2="0 0 20 * * *" -e CRON_CMD_2="/path/to/some/script" \
-e CRON_SCH_3="@every 3h" -e CRON_CMD_3="python" -e CRON_ARGS_3="/path/to/python.py" \
jeffkolb/multi-cron:latest
The command above adds 3 tasks to the multi-cron queue which:
Runs echo with the arguments I ran at midnight upon application start and then every day at midnight UTC
Runs a script located at /path/to/some/script at 8PM UTC with no arguments
Runs a python script located at /path/to/python.py every 3 hours
If you prefix the schedule with a ! character, the command will also run at startup
All commands should exit after running
| Field name | Mandatory? | Allowed values | Allowed special characters |
|---|---|---|---|
Seconds | No | 0-59 | * / , - |
Minutes | Yes | 0-59 | * / , - |
Hours | Yes | 0-23 | * / , - |
Day of month | Yes | 1-31 | * / , - ? |
Month | Yes | 1-12 or JAN-DEC | * / , - |
Day of week | Yes | 0-6 or SUN-SAT | * / , - ? |
Note that there are 6 fields (instead of 5 that cron uses) because as multi-cron resolution goes down to 1 second!
If you prefix the schedule with a ! character, the command will also run at startup
| Entry | Description | Equivalent To |
|---|---|---|
@yearly (or @annually) | Run once a year, midnight, Jan. 1st | 0 0 0 1 1 * |
@monthly | Run once a month, midnight, first of month | 0 0 0 1 * * |
@weekly | Run once a week, midnight on Sunday | 0 0 0 * * 0 |
@daily (or @midnight) | Run once a day, midnight | 0 0 0 * * * |
@hourly | Run once an hour, beginning of hour | 0 0 * * * * |
Thus, @every 1h30m10s would indicate a schedule that activates every 1 hour, 30 minutes, 10 seconds.
Asterisk ( * )
Slash ( / )
Comma ( , )
Hyphen ( - )
Question mark ( ? )
You may also schedule a job to execute at fixed intervals. This is supported by formatting the cron spec like this:
@every <duration>
Thus, @every 5s would run the command every 5 seconds
Time zones:
UTC however it is possible to override that setting by launching the container with an environmental variable (TZ) setLove2Merge:
Content type
Image
Digest
Size
3.9 MB
Last updated
about 7 years ago
docker pull jeffkolb/multi-cron