Skip to content

Commit 4e3dd38

Browse files
committed
supervisor: move cache process management in supervisor module
Signed-off-by: Matteo Cafasso <[email protected]>
1 parent fccad57 commit 4e3dd38

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

lib/supervisor.ex

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
1-
defmodule RabbitMQ.Supervisor do
1+
defmodule RabbitMQ.CacheSupervisor do
22
use DynamicSupervisor
33

4-
def start(_type, args) do
5-
DynamicSupervisor.start_link(__MODULE__, args, name: __MODULE__)
4+
require RabbitMQ.Cache
5+
6+
def start_link() do
7+
case DynamicSupervisor.start_link(__MODULE__, [], name: __MODULE__) do
8+
{:ok, _pid} -> :ok
9+
_ -> :error
10+
end
611
end
712

8-
def start_child(spec) do
9-
DynamicSupervisor.start_child(__MODULE__, spec)
13+
def start_cache(cache, options) do
14+
specifications = %{id: cache,
15+
start: {RabbitMQ.Cache, :start_link, [cache, options]}}
16+
17+
case DynamicSupervisor.start_child(__MODULE__, specifications) do
18+
{:ok, _} -> :ok
19+
{:error, {:already_started, _}} -> :ok
20+
_ -> :error
21+
end
1022
end
1123

12-
def terminate_child(name) do
13-
DynamicSupervisor.terminate_child(__MODULE__, name)
24+
def stop_cache(cache) do
25+
DynamicSupervisor.terminate_child(__MODULE__, RabbitMQ.Cache.process(cache))
1426
end
1527

1628
def init(_args) do

0 commit comments

Comments
 (0)