-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link queue supervisor and midwife for restarts
When a producer crashes it brings the queue's supervisor down with it. With enough database errors, the producer may crash repeatedly enough to exhaust restarts and bring down the DynamicSupervisor in charge of all queues. Now the supervisor is linked to the midwife to ensure that the midwife restarts as well, and it restarts all of the queues.
- Loading branch information
Showing
2 changed files
with
40 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
defmodule Oban.Nursery do | ||
@moduledoc false | ||
|
||
use Supervisor | ||
|
||
alias Oban.{Config, Midwife, Registry} | ||
|
||
@type opts :: [conf: Config.t(), name: GenServer.name()] | ||
|
||
@spec start_link(opts()) :: Supervisor.on_start() | ||
def start_link(opts) when is_list(opts) do | ||
Supervisor.start_link(__MODULE__, opts, name: opts[:name]) | ||
end | ||
|
||
@spec child_spec(opts()) :: Supervisor.child_spec() | ||
def child_spec(opts) do | ||
name = Keyword.fetch!(opts, :name) | ||
|
||
%{super(opts) | id: name} | ||
end | ||
|
||
@impl Supervisor | ||
def init(opts) do | ||
conf = Keyword.fetch!(opts, :conf) | ||
|
||
children = [ | ||
{DynamicSupervisor, name: Registry.via(conf.name, Foreman)}, | ||
{Midwife, conf: conf, name: Registry.via(conf.name, Midwife)} | ||
] | ||
|
||
Supervisor.init(children, max_restarts: 5, max_seconds: 30, strategy: :rest_for_one) | ||
end | ||
end |