Add src/hk_search_job_sup.erl
Browse files- src/hk_search_job_sup.erl +37 -0
src/hk_search_job_sup.erl
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
%%%-------------------------------------------------------------------
|
| 2 |
+
%%% @doc HK-SEARCH :: supervises one `hk_search_job' per active or
|
| 3 |
+
%%% recently-completed search job.
|
| 4 |
+
%%%
|
| 5 |
+
%%% `temporary', `simple_one_for_one': a search job is a one-shot
|
| 6 |
+
%%% pipeline run, not a long-lived resource like a browser session.
|
| 7 |
+
%%% It is never restarted by the supervisor -- a failed pipeline
|
| 8 |
+
%%% stage transitions the job's own state machine to `failed'
|
| 9 |
+
%%% (see `hk_search_job:fail/2') rather than crashing the process,
|
| 10 |
+
%%% so there is normally nothing for the supervisor to recover from;
|
| 11 |
+
%%% `temporary' just means an unexpected crash doesn't loop.
|
| 12 |
+
%%% @end
|
| 13 |
+
%%%-------------------------------------------------------------------
|
| 14 |
+
-module(hk_search_job_sup).
|
| 15 |
+
-behaviour(supervisor).
|
| 16 |
+
|
| 17 |
+
-export([start_link/0, init/1, start_job/1]).
|
| 18 |
+
|
| 19 |
+
start_link() ->
|
| 20 |
+
hk_sup_util:start_link_retry(
|
| 21 |
+
fun() -> supervisor:start_link({local, ?MODULE}, ?MODULE, []) end).
|
| 22 |
+
|
| 23 |
+
-spec start_job(map()) -> {ok, pid()} | {error, term()}.
|
| 24 |
+
start_job(Args) ->
|
| 25 |
+
supervisor:start_child(?MODULE, [Args]).
|
| 26 |
+
|
| 27 |
+
init([]) ->
|
| 28 |
+
SupFlags = #{strategy => simple_one_for_one, intensity => 20, period => 60},
|
| 29 |
+
Children = [
|
| 30 |
+
#{id => hk_search_job,
|
| 31 |
+
start => {hk_search_job, start_link, []},
|
| 32 |
+
restart => temporary,
|
| 33 |
+
shutdown => 5000,
|
| 34 |
+
type => worker,
|
| 35 |
+
modules => [hk_search_job]}
|
| 36 |
+
],
|
| 37 |
+
{ok, {SupFlags, Children}}.
|