containerpilot icon indicating copy to clipboard operation
containerpilot copied to clipboard

allow when:once and when:interval to coexist

Open tgross opened this issue 7 years ago • 5 comments

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.

tgross avatar Jun 26 '17 14:06 tgross

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.

tgross avatar Jun 27 '17 13:06 tgross

Noting for myself that there's a lot of under-the-hook implementation overlap between the issues in #435, #416, and #396

tgross avatar Aug 03 '17 13:08 tgross

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.

javaxplorer avatar Aug 22 '17 12:08 javaxplorer

Same, I'd like to send heartbeats that only start once the main process has started, not before.

gbmeuk avatar Nov 02 '17 18:11 gbmeuk

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'
      }
    }

gbmeuk avatar Jan 15 '18 14:01 gbmeuk