-module(pharos@internal@supervisor). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/pharos/internal/supervisor.gleam"). -export([start_link/3]). -export_type([alert_manager_spec/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(false). -type alert_manager_spec() :: {alert_manager_spec, pharos@alert:alert_data(), gleam@erlang@process:name(pharos@alert_manager:message())}. -file("src/pharos/internal/supervisor.gleam", 108). ?DOC(false). -spec poller_supervisor_child(pharos@config:config()) -> gleam@otp@supervision:child_specification(gleam@otp@static_supervisor:supervisor()). poller_supervisor_child(Config) -> Specs = lists:append( pharos@internal@poller:child_specs(erlang:element(2, Config)), pharos@internal@poller:probe_child_specs(erlang:element(4, Config)) ), Inner = gleam@list:fold( Specs, gleam@otp@static_supervisor:new(one_for_one), fun(Builder, Spec) -> gleam@otp@static_supervisor:add(Builder, Spec) end ), gleam@otp@static_supervisor:supervised(Inner). -file("src/pharos/internal/supervisor.gleam", 127). ?DOC(false). -spec event_manager_error_to_string(eparch@event_manager:start_error()) -> binary(). event_manager_error_to_string(Error) -> case Error of {already_started, _} -> <<"event bus already started"/utf8>>; {start_failed, Reason} -> Reason end. -file("src/pharos/internal/supervisor.gleam", 60). ?DOC(false). -spec event_bus_child(gleam@erlang@process:name(pharos@alert:alert_event())) -> gleam@otp@supervision:child_specification(pharos@event_bus:event_bus()). event_bus_child(Bus_name) -> gleam@otp@supervision:worker( fun() -> case pharos@event_bus:start_link(Bus_name) of {ok, {Pid, Bus}} -> {ok, {started, Pid, Bus}}; {error, Error} -> {error, {init_failed, event_manager_error_to_string(Error)}} end end ). -file("src/pharos/internal/supervisor.gleam", 134). ?DOC(false). -spec state_machine_error_to_string(eparch@state_machine:start_error()) -> binary(). state_machine_error_to_string(Error) -> case Error of init_timeout -> <<"alert manager init timeout"/utf8>>; {init_failed, Reason} -> Reason; {init_exited, _} -> <<"alert manager init exited"/utf8>>; {already_started, _} -> <<"alert manager name already registered"/utf8>> end. -file("src/pharos/internal/supervisor.gleam", 87). ?DOC(false). -spec alert_manager_child( pharos@alert:alert_data(), pharos@event_bus:event_bus(), gleam@erlang@process:name(pharos@alert_manager:message()) ) -> gleam@otp@supervision:child_specification(pharos@alert_manager:alert_manager()). alert_manager_child(Data, Bus, Name) -> gleam@otp@supervision:worker( fun() -> case pharos@alert_manager:start_link(Data, Bus, Name) of {ok, Handle} -> case gleam_erlang_ffi:process_named(Name) of {ok, Pid} -> {ok, {started, Pid, Handle}}; {error, _} -> {error, {init_failed, <<"alert manager registered name not found after start"/utf8>>}} end; {error, Error} -> {error, {init_failed, state_machine_error_to_string(Error)}} end end ). -file("src/pharos/internal/supervisor.gleam", 70). ?DOC(false). -spec alert_supervisor_child( gleam@erlang@process:name(pharos@alert:alert_event()), list(alert_manager_spec()) ) -> gleam@otp@supervision:child_specification(gleam@otp@static_supervisor:supervisor()). alert_supervisor_child(Bus_name, Manager_specs) -> Bus = pharos@event_bus:from_name(Bus_name), Inner = gleam@list:fold( Manager_specs, gleam@otp@static_supervisor:new(one_for_one), fun(Builder, Spec) -> {alert_manager_spec, Data, Name} = Spec, gleam@otp@static_supervisor:add( Builder, alert_manager_child(Data, Bus, Name) ) end ), gleam@otp@static_supervisor:supervised(Inner). -file("src/pharos/internal/supervisor.gleam", 44). ?DOC(false). -spec start_link( pharos@config:config(), gleam@erlang@process:name(pharos@alert:alert_event()), list(alert_manager_spec()) ) -> {ok, gleam@otp@actor:started(gleam@otp@static_supervisor:supervisor())} | {error, gleam@otp@actor:start_error()}. start_link(Config, Bus_name, Manager_specs) -> _pipe = gleam@otp@static_supervisor:new(rest_for_one), _pipe@1 = gleam@otp@static_supervisor:add(_pipe, event_bus_child(Bus_name)), _pipe@2 = gleam@otp@static_supervisor:add( _pipe@1, alert_supervisor_child(Bus_name, Manager_specs) ), _pipe@3 = gleam@otp@static_supervisor:add( _pipe@2, poller_supervisor_child(Config) ), gleam@otp@static_supervisor:start(_pipe@3).