| 1 |
|
-module(shurbej_version_sup). |
| 2 |
|
-behaviour(supervisor). |
| 3 |
|
|
| 4 |
|
-export([start_link/0, start_child/1, terminate_child/1]). |
| 5 |
|
-export([init/1]). |
| 6 |
|
|
| 7 |
|
start_link() -> |
| 8 |
1 |
supervisor:start_link({local, ?MODULE}, ?MODULE, []). |
| 9 |
|
|
| 10 |
|
start_child(LibraryId) -> |
| 11 |
212 |
supervisor:start_child(?MODULE, [LibraryId]). |
| 12 |
|
|
| 13 |
|
%% Ask the supervisor to shut down the version server for LibRef (if any). |
| 14 |
|
%% Safe no-op if no such child is running. |
| 15 |
|
terminate_child(LibRef) -> |
| 16 |
1 |
case global:whereis_name({shurbej_version, LibRef}) of |
| 17 |
:-( |
undefined -> ok; |
| 18 |
1 |
Pid -> supervisor:terminate_child(?MODULE, Pid) |
| 19 |
|
end. |
| 20 |
|
|
| 21 |
|
init([]) -> |
| 22 |
1 |
SupFlags = #{ |
| 23 |
|
strategy => simple_one_for_one, |
| 24 |
|
intensity => 5, |
| 25 |
|
period => 10 |
| 26 |
|
}, |
| 27 |
1 |
ChildSpec = #{ |
| 28 |
|
id => shurbej_version, |
| 29 |
|
start => {shurbej_version, start_link, []}, |
| 30 |
|
restart => transient, |
| 31 |
|
type => worker |
| 32 |
|
}, |
| 33 |
1 |
{ok, {SupFlags, [ChildSpec]}}. |