I'm currently trying to make one of ofelia, its fork chadburn or this scheduler work for me. The jobs I want to run are an emailer script and a backup job.
tl;dr: I would like to be able to define multiple "exec" jobs on a service via labels.
ofelia
is not exactly suitable because it either doesn't pick up updated containers after launch (when only one instance per host is deployed) and it doesn't respect project boundaries (when multiple ofelias are deployed, one per project).
Its fork chadburn
does pick up new containers but I don't like that all the logs for all projects are collected in the single instance; multiple instances don't behave either.
This scheduler is nice and minimal and can be deployed with each project. Your comment was actually how I found this scheduler. However, I can only define one scheduled job per service? Something like the following syntax would probably solve my issue:
...
labels:
net.reddec.scheduler.<jobname>.cron: "@daily"
net.reddec.scheduler.<jobname>.exec: "@daily"
I am afraid that this would add a lot of complexity, so I also tried to make the alternative "run" labels on separate services work. However the problem with that is that I cannot disable autostarting the container immediately while running docker-compose up -d
. This could be achieved with profiles but then your scheduler does not pick up the container at all, since the container is never created โ hence the labels can never be read.
In my tests it appears that when I just let the container autostart with the rest, then
- immediate invocation that could have undesirable side-effects if it runs too early
the first "scheduled" invocation of the container seems to be skipped False alarm; it's run properly but the stdout
is lost somehow.
idea: schedule profiles
Maybe you could add labels on the scheduler itself to start certain profiles on a schedule? Something like this:
version: "3"
services:
app:
image: myapp:latest
...
backup:
image: alpine:latest
command: [ "/bin/ash", "-c", "id; pwd" ]
profiles: [ backup ]
cron:
image: ghcr.io/reddec/compose-scheduler:1.0.0
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
labels:
# net.reddec.scheduler.<profile>: <schedule>
net.reddec.scheduler.backup: "@daily"
Although, I am afraid this won't work either, since this profiles:
information never reaches the Docker daemon being a docker-compose
feature ...