View Source partisan_gen_supervisor behaviour (partisan v5.0.0-beta.15)

This module is an adaptation of Erlang's supervisor module.

The only use case in need of this module instead of OTP's supervisor is when you need to supervise remote processes i.e. if you just need to supervise local partisan_gen_server or partisan_gen_statem processes you can still use OTP's supervisor. It replaces all the usage of modules gen_server and functions erlang:is_pid/0 and erlang:monitor/2 with their Partisan counterparts.

Link to this section Summary

Link to this section Types

-type auto_shutdown() :: never | any_significant | all_significant.
-type call() :: which_children | count_children | {_, _}.
XXX: refine
-type child() :: undefined | pid2().
-type child_id() :: term().
-type child_rec() :: #child{}.
-type child_spec() ::
    #{id := child_id(),
      start := mfargs(),
      restart => restart(),
      significant => significant(),
      shutdown => shutdown(),
      type => worker(),
      modules => modules()} |
    {Id :: child_id(),
     StartFunc :: mfargs(),
     Restart :: restart(),
     Shutdown :: shutdown(),
     Type :: worker(),
     Modules :: modules()}.
-type children() :: {Ids :: [child_id()], Db :: #{child_id() => child_rec()}}.
-type init_sup_name() :: sup_name() | self.
-type mfargs() :: {M :: module(), F :: atom(), A :: [term()] | undefined}.
-type modules() :: [module()] | dynamic.
-type pid2() :: pid() | partisan_remote_ref:p().
-type restart() :: permanent | transient | temporary.
-type shutdown() :: brutal_kill | timeout().
-type significant() :: boolean().
-type startchild_err() :: already_present | {already_started, Child :: child()} | term().
-type startchild_ret() ::
    {ok, Child :: child()} | {ok, Child :: child(), Info :: term()} | {error, startchild_err()}.
-type state() :: #state{}.
-type stop_rsn() ::
    {shutdown, term()} |
    {bad_return, {module(), init, term()}} |
    {bad_start_spec, term()} |
    {start_spec, term()} |
    {supervisor_data, term()}.
-type strategy() :: one_for_all | one_for_one | rest_for_one | simple_one_for_one.
-type sup_flags() ::
    #{strategy => strategy(),
      intensity => non_neg_integer(),
      period => pos_integer(),
      auto_shutdown => auto_shutdown()} |
    {RestartStrategy :: strategy(), Intensity :: non_neg_integer(), Period :: pos_integer()}.
-type sup_name() ::
    {local, Name :: atom()} | {global, Name :: term()} | {via, Module :: module(), Name :: any()}.
-type sup_ref() ::
    (Name :: atom()) |
    {Name :: atom(), Node :: node()} |
    {global, Name :: term()} |
    {via, Module :: module(), Name :: any()} |
    pid2().
-type worker() :: worker | supervisor.

Link to this section Callbacks

-callback init(Args :: term()) -> {ok, {SupFlags :: sup_flags(), [ChildSpec :: child_spec()]}} | ignore.

Link to this section Functions

Link to this function

check_childspecs(ChildSpecs)

View Source
-spec check_childspecs(ChildSpecs) -> Result
                    when ChildSpecs :: [child_spec()], Result :: ok | {error, Error :: term()}.
Link to this function

check_childspecs(ChildSpecs, AutoShutdown)

View Source
-spec check_childspecs(ChildSpecs, AutoShutdown) -> Result
                    when
                        ChildSpecs :: [child_spec()],
                        AutoShutdown :: undefined | auto_shutdown(),
                        Result :: ok | {error, Error :: term()}.
Link to this function

code_change(_, State, _)

View Source
-spec code_change(term(), state(), term()) -> {ok, state()} | {error, term()}.
-spec count_children(SupRef) -> PropListOfCounts
                  when
                      SupRef :: sup_ref(),
                      PropListOfCounts :: [Count],
                      Count ::
                          {specs, ChildSpecCount :: non_neg_integer()} |
                          {active, ActiveProcessCount :: non_neg_integer()} |
                          {supervisors, ChildSupervisorCount :: non_neg_integer()} |
                          {workers, ChildWorkerCount :: non_neg_integer()}.
Link to this function

delete_child(SupRef, Id)

View Source
-spec delete_child(SupRef, Id) -> Result
                when
                    SupRef :: sup_ref(),
                    Id :: child_id(),
                    Result :: ok | {error, Error},
                    Error :: running | restarting | not_found | simple_one_for_one.
Link to this function

format_log(Report, FormatOpts0)

View Source
Link to this function

get_callback_module(Pid)

View Source
-spec get_callback_module(Pid) -> Module when Pid :: pid(), Module :: atom().
Link to this function

get_childspec(SupRef, Id)

View Source
-spec get_childspec(SupRef, Id) -> Result
                 when
                     SupRef :: sup_ref(),
                     Id :: pid2() | child_id(),
                     Result :: {ok, child_spec()} | {error, Error},
                     Error :: not_found.
Link to this function

handle_call(_, From, State)

View Source
-spec handle_call(call(), term(), state()) -> {reply, term(), state()}.
-spec handle_cast({try_again_restart, child_id() | {restarting, pid2()}}, state()) ->
               {noreply, state()} | {stop, shutdown, state()}.
-spec handle_info(term(), state()) -> {noreply, state()} | {stop, shutdown, state()}.
-spec init({init_sup_name(), module(), [term()]}) -> {ok, state()} | ignore | {stop, stop_rsn()}.
Link to this function

restart_child(SupRef, Id)

View Source
-spec restart_child(SupRef, Id) -> Result
                 when
                     SupRef :: sup_ref(),
                     Id :: child_id(),
                     Result ::
                         {ok, Child :: child()} |
                         {ok, Child :: child(), Info :: term()} |
                         {error, Error},
                     Error :: running | restarting | not_found | simple_one_for_one | term().
Link to this function

start_child(SupRef, ChildSpec)

View Source
-spec start_child(SupRef, ChildSpec) -> startchild_ret()
               when SupRef :: sup_ref(), ChildSpec :: child_spec() | (List :: [term()]).
Link to this function

start_link(Module, Args)

View Source
-spec start_link(Module, Args) -> startlink_ret() when Module :: module(), Args :: term().
Link to this function

start_link(SupName, Module, Args)

View Source
-spec start_link(SupName, Module, Args) -> startlink_ret()
              when SupName :: sup_name(), Module :: module(), Args :: term().
Link to this function

terminate(Reason, State)

View Source
-spec terminate(term(), state()) -> ok.
Link to this function

terminate_child(SupRef, Id)

View Source
-spec terminate_child(SupRef, Id) -> Result
                   when
                       SupRef :: sup_ref(),
                       Id :: pid2() | child_id(),
                       Result :: ok | {error, Error},
                       Error :: not_found | simple_one_for_one.
-spec which_children(SupRef) -> [{Id, Child, Type, Modules}]
                  when
                      SupRef :: sup_ref(),
                      Id :: child_id() | undefined,
                      Child :: child() | restarting,
                      Type :: worker(),
                      Modules :: modules().