Github user iilyak commented on a diff in the pull request:
https://github.com/apache/couchdb-couch-epi/pull/12#discussion_r40800310
--- Diff: src/couch_epi_sup.erl ---
@@ -32,13 +47,216 @@
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
+plugin_childspecs(Plugin, Children) ->
+ Plugins = application:get_env(couch_epi, plugins, []),
+ plugin_childspecs(Plugin, Plugins, Children).
+
%% ===================================================================
%% Supervisor callbacks
%% ===================================================================
init([]) ->
- Children = [
- ?CHILD(couch_epi_server, worker),
- ?SUP(couch_epi_keeper_sup, [])
+ {ok, { {one_for_one, 5, 10}, keepers()} }.
+
+%% ------------------------------------------------------------------
+%% Internal Function Definitions
+%% ------------------------------------------------------------------
+
+keepers() ->
+ Plugins = application:get_env(couch_epi, plugins, []),
+ Definitions0 = couch_epi_plugin:grouped_definitions(Plugins),
+ Definitions1 = reorder(Definitions0),
+ Children = keeper_childspecs(Definitions1),
+ remove_duplicates(Children).
+
+plugin_childspecs(Plugin, Plugins, Children) ->
+ Definitions = couch_epi_plugin:grouped_definitions([Plugin]),
+ ExtraChildren = couch_epi_plugin:plugin_processes(Plugin, Plugins),
+ merge(ExtraChildren, Children) ++ childspecs(Definitions).
+
+childspecs(Definitions) ->
+ lists:map(fun({{Kind, Key}, Defs}) ->
+ CodeGen = couch_epi_plugin:codegen(Kind),
+ Handle = CodeGen:get_handle(Key),
+ Modules = lists:append([modules(Spec) || {_App, Spec} <- Defs]),
+ Name = service_name(Key) ++ "|" ++ atom_to_list(Kind),
+ code_monitor(Name, [Handle], [Handle|Modules])
+ end, Definitions).
+
+%% ------------------------------------------------------------------
+%% Helper Function Definitions
+%% ------------------------------------------------------------------
+
+reorder(Definitions) ->
+ lists:sort(fun(A, B) ->
+ kinds_order(A) =< kinds_order(B)
+ end, Definitions).
+
+kinds_order({{providers, _Key}, _Specs}) -> 3;
+kinds_order({{services, _Key}, _Specs}) -> 1;
+kinds_order({{data_providers, _Key}, _Specs}) -> 4;
+kinds_order({{data_subscriptions, _Key}, _Specs}) -> 2.
+
+remove_duplicates(Definitions) ->
+ remove_duplicates(Definitions, []).
--- End diff --
We need children to be ordered in a particular way. But we probably can
switch the order of operations
[here](https://github.com/cloudant/couchdb-couch-epi/blob/simplify_couch_epi/src/couch_epi_sup.erl#L68:L70).
I'll think about it. Thank you.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---