Github user iilyak commented on a diff in the pull request:

    https://github.com/apache/couchdb-couch-epi/pull/4#discussion_r34680147
  
    --- Diff: src/couch_epi_data.erl ---
    @@ -88,7 +88,8 @@ handle_call(stop, _From, State) ->
     handle_call(_Request, _From, State) ->
         {reply, ok, State}.
     
    -handle_cast(init, #state{pending = Pending} = State) ->
    +handle_cast(init, #state{pending = Pending, handle = Handle} = State) ->
    +    couch_epi_module_keeper:maybe_start_keeper(couch_epi_data_gen, Handle),
    --- End diff --
    
    > a cast that starts a supervised child?
    
    good catch
    
    > Is it not possible to get the ordering right during application start?
    
    It doesn't look like it is possible. Here is an example. Let's say we want 
to add `chttpd_handlers` service. Internally under the hood we would generate a 
new module `couch_epi_functions_gen_chttpd_handlers`. So we need the 
module_keeper process registered under that name. Let's say we implement 
`couch_epi:register_service` which we intend to call from supervisor of the app 
where we want to place the service (in our case `chttpd`). That would mean that 
we would start the module_keeper process when `chttpd` app starts. The current 
order of the apps is:
    ```
    06:41:36.898 [info] Application couch_epi started on node nonode@nohost
    06:41:37.077 [info] Application couch started on node nonode@nohost
    06:41:37.135 [info] Application mem3 started on node nonode@nohost
    06:41:37.296 [info] Application chttpd started on node nonode@nohost
    06:41:37.350 [info] Application global_changes started on node nonode@nohost
    ```
    As you can see `mem3` is started before `chttpd`. Since we define 
`_membership` handler in `mem3` it will not work since the module_keeper 
process wouldn't be there at that time.
    
    I'm still thinking how we can solve this problem using supervision.


---
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.
---

Reply via email to