During application start up after
Supervisor.start_link(children, opts) sets up the supervision tree with all attendant processes I want to resume an Oban queue I configured to be paused by default.
The use case is that in my deployment I have a migration phase and a service startup phase. The paused queue should only be resumed in the service startup phase. Each phase uses the same Docker image to boot (a precompiled Elixir release). The migration phase uses this container for a Kubernetes initContainer to do database migrations and other initialization task. The service startup phase uses the same container image to run an Elixir service.
Since the migration container terminates prior to some async jobs finishing, effectively giving false positives for job completion, we changed our approach to save the async jobs immediately to the DB with Oban to the paused queue. In the next phase the service deployment resumes that queue and process all the jobs so we can be more sure the jobs will complete.
An environment variable controls whether or not to resume this job processing. That variable is false in the migration environment and true in the service environment. When the variable is true I want the queue to be resumed, like the following:
defmodule MyApp.Application do @my_env_var Application.fetch_env!(:myapp, :some_var) def start(_, _) do topologies ... children ... Supervisor.start_link(children, opts) if @my_env_var do Oban.resume_queue(queue: :my queue) end end end
and in releases.exs
import Config config: :myapp, myvar: System.get_env("PERFORM_JOB")
Is this how it is supposed to work?