Skip to content

Commit

Permalink
Explicitly pause queues when shutdown begins
Browse files Browse the repository at this point in the history
A call to `Producer.shutdown/1` was erroneously removed during the
DynamicSupervisor queue refactor.
  • Loading branch information
sorentwo committed Jun 28, 2023
1 parent 68dbebf commit fa36e3c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/oban/queue/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ defmodule Oban.Queue.Supervisor do
watch_opts = [
foreman: fore_name,
name: watch_name,
producer: prod_name,
shutdown: conf.shutdown_grace_period
]

Expand Down
10 changes: 7 additions & 3 deletions lib/oban/queue/watchman.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ defmodule Oban.Queue.Watchman do

use GenServer

alias Oban.Queue.Producer

@type option ::
{:name, module()}
| {:foreman, identifier()}
{:foreman, GenServer.name()}
| {:name, module()}
| {:producer, GenServer.name()}
| {:shutdown, timeout()}

defmodule State do
@moduledoc false

defstruct [:foreman, :shutdown, interval: 10]
defstruct [:foreman, :producer, :shutdown, interval: 10]
end

@spec child_spec([option]) :: Supervisor.child_spec()
Expand Down Expand Up @@ -47,6 +50,7 @@ defmodule Oban.Queue.Watchman do
# There is a chance that the foreman doesn't exist, and we never want to raise another error
# as part of the shut down process.
try do
:ok = Producer.shutdown(state.producer)
:ok = wait_for_executing(state)
catch
:exit, _reason -> :ok
Expand Down
2 changes: 1 addition & 1 deletion test/oban_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule ObanTest do
name =
start_supervised_oban!(
queues: [alpha: 1],
shutdown_grace_period: 10,
shutdown_grace_period: 40,
stage_interval: 10
)

Expand Down

0 comments on commit fa36e3c

Please sign in to comment.