Current section

Files

Jump to
glixir src glixir@supervisor.erl
Raw

src/glixir@supervisor.erl

-module(glixir@supervisor).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/glixir/supervisor.gleam").
-export([start_dynamic_supervisor_named/1, start_dynamic_supervisor_simple/0, start_dynamic_child_simple/2, child_spec/4, child_spec_with_restart/5, delete_child/2, restart_child/2, which_children/1, count_children/1, terminate_child/2, start_link/1, start_link_default/0, start_link_named/2, start_child_simple/2]).
-export_type([supervisor/0, started/1, restart_strategy/0, supervisor_strategy/0, child_type/0, supervisor_error/0, start_error/0, child_operation_error/0, delete_child_result/0, restart_child_result/0, terminate_child_result/0, child_counts/0, child_status/0, child_modules/0, child_info_result/0, simple_child_spec/0, dynamic_supervisor_result/0, dynamic_child_result/0, dynamic_terminate_result/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Dynamic supervisor support for runtime process management\n"
" \n"
" This module provides a Gleam-friendly interface to Elixir's DynamicSupervisor,\n"
" using our Elixir helper module for clean data conversion.\n"
).
-opaque supervisor() :: {supervisor, gleam@erlang@process:pid_()}.
-type started(EMZ) :: {started, gleam@erlang@process:pid_(), EMZ}.
-type restart_strategy() :: permanent | temporary | transient.
-type supervisor_strategy() :: one_for_one | one_for_all | rest_for_one.
-type child_type() :: worker | supervisor_child.
-type supervisor_error() :: {start_error, binary()} |
{child_start_error, binary(), binary()} |
{child_not_found, binary()} |
{already_started, binary()} |
{invalid_child_spec, binary()}.
-type start_error() :: init_timeout |
{init_failed, binary()} |
{init_exited, gleam@erlang@process:exit_reason()}.
-type child_operation_error() :: running |
restarting |
not_found |
simple_one_for_one |
{other_error, gleam@dynamic:dynamic_()}.
-type delete_child_result() :: delete_child_ok |
{delete_child_error, child_operation_error()}.
-type restart_child_result() :: {restart_child_ok, gleam@erlang@process:pid_()} |
{restart_child_ok_already_started, gleam@erlang@process:pid_()} |
{restart_child_error, child_operation_error()}.
-type terminate_child_result() :: terminate_child_ok |
{terminate_child_error, child_operation_error()}.
-type child_counts() :: {child_counts,
integer(),
integer(),
integer(),
integer()}.
-type child_status() :: {child_pid, gleam@erlang@process:pid_()} |
child_restarting |
child_undefined.
-type child_modules() :: modules_dynamic |
{modules_list, list(gleam@erlang@atom:atom_())} |
modules_empty.
-type child_info_result() :: {child_info,
gleam@dynamic:dynamic_(),
child_status(),
child_type(),
child_modules()}.
-type simple_child_spec() :: {simple_child_spec,
binary(),
gleam@erlang@atom:atom_(),
gleam@erlang@atom:atom_(),
list(gleam@dynamic:dynamic_()),
restart_strategy(),
integer(),
child_type()}.
-type dynamic_supervisor_result() :: {dynamic_supervisor_ok,
gleam@erlang@process:pid_()} |
{dynamic_supervisor_error, gleam@dynamic:dynamic_()}.
-type dynamic_child_result() :: {dynamic_start_child_ok,
gleam@erlang@process:pid_()} |
{dynamic_start_child_error, gleam@dynamic:dynamic_()}.
-type dynamic_terminate_result() :: dynamic_terminate_child_ok |
{dynamic_terminate_child_error, gleam@dynamic:dynamic_()}.
-file("src/glixir/supervisor.gleam", 214).
-spec atom_to_string(gleam@erlang@atom:atom_()) -> binary().
atom_to_string(Atom_val) ->
erlang:atom_to_binary(Atom_val).
-file("src/glixir/supervisor.gleam", 219).
-spec restart_to_string(restart_strategy()) -> binary().
restart_to_string(Restart) ->
case Restart of
permanent ->
<<"permanent"/utf8>>;
temporary ->
<<"temporary"/utf8>>;
transient ->
<<"transient"/utf8>>
end.
-file("src/glixir/supervisor.gleam", 228).
-spec child_type_to_string(child_type()) -> binary().
child_type_to_string(Child_type) ->
case Child_type of
worker ->
<<"worker"/utf8>>;
supervisor_child ->
<<"supervisor"/utf8>>
end.
-file("src/glixir/supervisor.gleam", 236).
-spec spec_to_map(simple_child_spec()) -> gleam@dynamic:dynamic_().
spec_to_map(Spec) ->
gleam@dynamic:properties(
[{gleam_stdlib:identity(<<"id"/utf8>>),
gleam_stdlib:identity(erlang:element(2, Spec))},
{gleam_stdlib:identity(<<"start_module"/utf8>>),
gleam_stdlib:identity(atom_to_string(erlang:element(3, Spec)))},
{gleam_stdlib:identity(<<"start_function"/utf8>>),
gleam_stdlib:identity(atom_to_string(erlang:element(4, Spec)))},
{gleam_stdlib:identity(<<"start_args"/utf8>>),
erlang:list_to_tuple(erlang:element(5, Spec))},
{gleam_stdlib:identity(<<"restart"/utf8>>),
gleam_stdlib:identity(
restart_to_string(erlang:element(6, Spec))
)},
{gleam_stdlib:identity(<<"shutdown"/utf8>>),
gleam_stdlib:identity(
erlang:integer_to_binary(erlang:element(7, Spec))
)},
{gleam_stdlib:identity(<<"type"/utf8>>),
gleam_stdlib:identity(
child_type_to_string(erlang:element(8, Spec))
)}]
).
-file("src/glixir/supervisor.gleam", 268).
?DOC(" Start a named dynamic supervisor using our Elixir helper\n").
-spec start_dynamic_supervisor_named(binary()) -> {ok, supervisor()} |
{error, supervisor_error()}.
start_dynamic_supervisor_named(Name) ->
case 'Elixir.Glixir.Supervisor':start_dynamic_supervisor_named(Name) of
_ ->
{error,
{start_error,
<<"Not yet implemented - need result decoding"/utf8>>}}
end.
-file("src/glixir/supervisor.gleam", 278).
?DOC(" Start a simple dynamic supervisor with defaults\n").
-spec start_dynamic_supervisor_simple() -> {ok, supervisor()} |
{error, supervisor_error()}.
start_dynamic_supervisor_simple() ->
case 'Elixir.Glixir.Supervisor':start_dynamic_supervisor_simple() of
_ ->
{error,
{start_error,
<<"Not yet implemented - need result decoding"/utf8>>}}
end.
-file("src/glixir/supervisor.gleam", 286).
?DOC(" Start a child in a DynamicSupervisor using our simplified interface\n").
-spec start_dynamic_child_simple(supervisor(), simple_child_spec()) -> {ok,
gleam@erlang@process:pid_()} |
{error, binary()}.
start_dynamic_child_simple(Supervisor, Spec) ->
{supervisor, Supervisor_pid} = Supervisor,
Spec_map = spec_to_map(Spec),
case 'Elixir.Glixir.Supervisor':start_dynamic_child(
Supervisor_pid,
Spec_map
) of
_ ->
{error, <<"Not yet implemented - need result decoding"/utf8>>}
end.
-file("src/glixir/supervisor.gleam", 304).
?DOC(" Create a simple child specification - the easy way to define children\n").
-spec child_spec(binary(), binary(), binary(), list(gleam@dynamic:dynamic_())) -> simple_child_spec().
child_spec(Id, Module, Function, Args) ->
{simple_child_spec,
Id,
erlang:binary_to_atom(Module),
erlang:binary_to_atom(Function),
Args,
permanent,
5000,
worker}.
-file("src/glixir/supervisor.gleam", 322).
?DOC(" Create a child spec with custom restart strategy\n").
-spec child_spec_with_restart(
binary(),
binary(),
binary(),
list(gleam@dynamic:dynamic_()),
restart_strategy()
) -> simple_child_spec().
child_spec_with_restart(Id, Module, Function, Args, Restart) ->
{simple_child_spec,
Id,
erlang:binary_to_atom(Module),
erlang:binary_to_atom(Function),
Args,
Restart,
5000,
worker}.
-file("src/glixir/supervisor.gleam", 341).
?DOC(" Delete a child specification from the supervisor\n").
-spec delete_child(supervisor(), binary()) -> delete_child_result().
delete_child(Supervisor, Child_id) ->
{supervisor, Pid} = Supervisor,
'Elixir.Glixir.Supervisor':delete_child(
Pid,
gleam_stdlib:identity(Child_id)
).
-file("src/glixir/supervisor.gleam", 350).
?DOC(" Restart a child process\n").
-spec restart_child(supervisor(), binary()) -> restart_child_result().
restart_child(Supervisor, Child_id) ->
{supervisor, Pid} = Supervisor,
'Elixir.Glixir.Supervisor':restart_child(
Pid,
gleam_stdlib:identity(Child_id)
).
-file("src/glixir/supervisor.gleam", 359).
?DOC(" Get information about all child processes\n").
-spec which_children(supervisor()) -> list(child_info_result()).
which_children(Supervisor) ->
{supervisor, Pid} = Supervisor,
'Elixir.Glixir.Supervisor':which_children(Pid).
-file("src/glixir/supervisor.gleam", 365).
?DOC(" Count children by type and status\n").
-spec count_children(supervisor()) -> child_counts().
count_children(Supervisor) ->
{supervisor, Pid} = Supervisor,
'Elixir.Glixir.Supervisor':count_children(Pid).
-file("src/glixir/supervisor.gleam", 371).
?DOC(" Terminate a child process\n").
-spec terminate_child(supervisor(), binary()) -> terminate_child_result().
terminate_child(Supervisor, Child_id) ->
{supervisor, Pid} = Supervisor,
'Elixir.Glixir.Supervisor':terminate_child(
Pid,
gleam_stdlib:identity(Child_id)
).
-file("src/glixir/supervisor.gleam", 384).
?DOC(" Start a new dynamic supervisor with options map (legacy interface)\n").
-spec start_link(list({binary(), gleam@dynamic:dynamic_()})) -> {ok,
supervisor()} |
{error, supervisor_error()}.
start_link(_) ->
start_dynamic_supervisor_simple().
-file("src/glixir/supervisor.gleam", 392).
?DOC(" Start a basic dynamic supervisor with default one_for_one strategy\n").
-spec start_link_default() -> {ok, supervisor()} | {error, supervisor_error()}.
start_link_default() ->
start_dynamic_supervisor_simple().
-file("src/glixir/supervisor.gleam", 397).
?DOC(" Start a named dynamic supervisor (legacy interface)\n").
-spec start_link_named(binary(), list({binary(), gleam@dynamic:dynamic_()})) -> {ok,
supervisor()} |
{error, supervisor_error()}.
start_link_named(Name, _) ->
start_dynamic_supervisor_named(Name).
-file("src/glixir/supervisor.gleam", 405).
?DOC(" Start a child using SimpleChildSpec (legacy interface)\n").
-spec start_child_simple(supervisor(), simple_child_spec()) -> {ok,
gleam@erlang@process:pid_()} |
{error, binary()}.
start_child_simple(Supervisor, Spec) ->
start_dynamic_child_simple(Supervisor, Spec).