-
-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support alternative namespacing in PG notifier
By default, all Oban instances using the same `prefix` option would receive notifications from each other. Now you can use the `namespace` option to separate instances that are in the same cluster _without_ changing the `prefix`. Addresses #1065
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 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,28 @@ | ||
defmodule Oban.Notifiers.PGTest do | ||
use Oban.Case, async: true | ||
|
||
alias Oban.Notifier | ||
alias Oban.Notifiers.PG | ||
|
||
describe "namespacing" do | ||
test "namespacing by configured prefix without an override" do | ||
name_1 = start_supervised_oban!(notifier: PG, prefix: "pg_test") | ||
name_2 = start_supervised_oban!(notifier: PG, prefix: "pg_test") | ||
|
||
:ok = Notifier.listen(name_1, :signal) | ||
:ok = Notifier.notify(name_2, :signal, %{incoming: "message"}) | ||
|
||
assert_receive {:notification, :signal, %{"incoming" => "message"}} | ||
end | ||
|
||
test "overriding the default namespace" do | ||
name_1 = start_supervised_oban!(notifier: {PG, namespace: :pg_test}, prefix: "pg_a") | ||
name_2 = start_supervised_oban!(notifier: {PG, namespace: :pg_test}, prefix: "pg_b") | ||
|
||
:ok = Notifier.listen(name_1, :signal) | ||
:ok = Notifier.notify(name_2, :signal, %{incoming: "message"}) | ||
|
||
assert_receive {:notification, :signal, %{"incoming" => "message"}} | ||
end | ||
end | ||
end |