How to correctly express A>B>C task dependency?

I have a group with 3 tasks:

  • database
  • init task
  • app

I want to first start database, wait for tcp health check, run the (idempotent) init task that ensures migrations have run, then start the app. This should be relatively simple but I have two problems:

  • The companion sidecar docs mention things like log shippers but not databases, and the init task docs show a convoluted wait-for-db example with netcat instead of relying on health check. This makes me think that this is the wrong approach for working with databases.
  • If both database and init task are prestart then they will start at ~the same time, and the init task will die due not being able to connect to db. This can potentially work if we repeatedly restart the init task with enough grace period for db to likely come up, but this is not a clean or deterministic solution.

Is this the wrong way of approaching this problem? I could potentially move the init logic to the app task, but my actual setup is more complex than this simplified example (multiple app tasks which may enter lock contention if they all try to run init at the same time) so this would not be a clean solution.

ok, I am trying an even simpler arrangement with just DB and a dependent task and even this doesn’t seem to be working:

  • db task (lifecycle prestart sidecar) starts
  • without waiting for a passing healthcheck on db, the second task starts (lifecycle main), dies immediately because the db isn’t ready
  • db task gets killed because of sibling failure
  • cycle repeats

am I fundamentally misunderstanding the lifecycle stanza for sidecars? is it not actually meant to have the prestart task start before main?

Are you able to post a job spec?

Having lifecycle.sidecar enabled means the task will run side by side with the main task, it sounds like you want to have sidecar = false (which is also the default).