containerpilot
containerpilot copied to clipboard
allow when:once and when:interval to coexist
Currently a user can configure when: { interval: "x" }
, which has a job run every interval
, or the user can configure when: { once: "y" }
which has the job run once a specific event occurs. We should also support when: { interval: "x" , once: "y" }
, which has the job run once a specific event occurs and then every interval
after that.
This can probably be tied to #415 inasmuch as we'll need to track state on whether a job has been started. Off the top of my head I'd suggest we add this to the JobStatus
struct, and have a job move from unstarted
-> unknown
-> healthy
.
The groundwork for this is done in https://github.com/joyent/containerpilot/pull/418 but a subsequent PR will need to be done to allow (and test) the configuration change.
Noting for myself that there's a lot of under-the-hook implementation overlap between the issues in #435, #416, and #396
Got into the situation that I actually needed this; I have a database container and I want to run repeating backup jobs when the database is healthy. So now I can only use 'interval' and since there's no delay, the first backup is triggered instantly and then fails as the database is still starting up.
I can think of two possible implementations:
- Start the 'interval' once the 'when' condition is met, then stop caring about the 'when'.
- Start 'interval' immediately and only execute when the 'when' condition is met.
Same, I'd like to send heartbeats that only start once the main process has started, not before.
Solved our own issue with:
{
name: 'apache-fwdproxy',
exec: '/usr/local/bin/app-manage start',
restarts: 3,
port: '33000',
health: {
exec: '/usr/local/bin/app-manage health',
interval: 10,
ttl: 30,
timeout: 3,
},
tags: [
'apache',
'googleproxy'
],
consul: {
enableTagOverride: true,
deregisterCriticalServiceAfter: '10m'
},
when: {
source: 'pre-start',
once: 'exitSuccess'
}
}
{
name: 'scheduling-status-healthy',
exec: ['zabbix_sender',
'-c', '/etc/coprocesses/zabbix/zabbix_agentd.conf',
'--key', 'container.state',
'--value', '1'],
when: {
source: 'apache-fwdproxy',
each: 'healthy'
}
}