Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep worker alive if update_documents fails #37

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tcrossland
Copy link
Contributor

See #24


defp start_worker(config) do
{:ok, pid} = start_supervised({OpenIDConnect.Worker, config})
Process.sleep(10) # allow :update_documents to run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing sleep during a test isn't ideal. It would be better if the pid of the test could be added as an option and if present the worker would notify the pid when the document was updated. Then the test would assert_received for that message and timeout/fail if it doesn't happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. The test doesn't really need to be notified when update_documents completes (it's mocked), but the :update_documents should be in the worker's queue before the test continues.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as it stands, I think the PR's architecture implementation is wrong. The update_documents function should be blocking. I'd like to see failing test cases and work back from there to a solution

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update_documents is still blocking. It was already a handle_info before this PR, I haven't changed that, and it schedules itself periodically, as before. I deferred it's invocation from init/1 to allow the worker (and it's supervision tree) to remain alive in the case of a temporary network error (domain resolution failure, for example).

Feel free to look at alternatives (#30).

:ignore
end

def init(provider_configs) do
def init({provider_configs, notify_pid}) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead this should be a separate functional call that is something like:

def init({provider_configs, pid}) is_id(pid) do
   {:ok, state} = init(provider_configs)
   Process.send(pid, :ready)
   {:ok, state}
end

you can drop the handle_info function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Third time lucky. I'm using Process.send_after rather than Process.send to ensure that update_documents will be in the workers inbox before the test proceeds.

@tcrossland
Copy link
Contributor Author

@bcardarella sorry to bother but have you had a chance to give this any consideration? At the moment, without this PR or something similar, an nxdomain error or any other network error during update_documents will kill the worker, it's supervision tree and the whole application if it's configured following the documented instructions here. Happy to make further changes if you think there's anything that needs improving with this approach.

@bcardarella
Copy link
Member

sorry this has gone stale, DY doesn't have internal resources to support the library so I am going to start seeking an external maintainer.

@tcrossland
Copy link
Contributor Author

sorry this has gone stale, DY doesn't have internal resources to support the library so I am going to start seeking an external maintainer.

No problem... I'd be happy to help in a limited capacity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants