Closed juanpabloaj closed 3 years ago
Hi @juanpabloaj, thank you very much for your kind words - I thrilled to know that you like it :heart:
In regards to your question:
In normal circumstances when a "worker" process (like the Naive.Trader
) is supervised by the Supervisor
, there's a built-in system that will stop it from restarting the worker forever: https://hexdocs.pm/elixir/1.12/Supervisor.Spec.html#supervise/2-options
(I'm talking about :max_restarts
[defaults to 3] and :max_seconds
[defaults to 5]).
This would be the first "Elixir way" of fixing this problem - it would quickly die 3 times and it wouldn't try to restart it.
but we are not using this mechanism as we disabled it by setting the Naive.Trader
to restart: :temporary
we are only relying on our Naive.Leader
process to react to the :DOWN
info message. At this moment we don't have any implementation that would count the number of restarts etc - so the Naive.Leader
process will keep on restarting the "broken"(for example: because of configuration) Naive.Trader
process.
One way to "fix" that would be to add the case
as you pointed out and instead of calling the Naive.Leader
to tell it to not restart the process. We could return {:stop, :your_special_error_not_restart, state}
from the handle_info
inside the Trader
then we could write the:
def handle_info(
{:DOWN, _ref, :process, trader_pid, :your_special_error_not_restart},
%{traders: traders, symbol: symbol, settings: settings} = state
) do ....
inside the Naive.Leader
Inside the Naive.Leader
's handler you would decide what you want to do with a specific error.
In case of normal supervision it would be enough to log a warning and return {:stop, :normal, state}
but this would stop just a single process that suffered from error - if you would want to stop all of the ones assigned to the symbol you would need somehow terminate tree from above (as you suggested by using the Naive.Leader
process).
I hope that helps,
PS. I would greatly appreciate it if we could recreate this inside GitHub Discussions
that I just enabled for exact topics like this. If you could just copy across your question there and I will copy this one so other people could read it and possibly join the conversation or open other questions/topics. I would greatly appreciate that :+1: If you would have further questions - we can chat there if you don't mind.
Thank you once again for your feedback and contributions to make this book better :rocket:
@Cinderella-Man thanks, for your book, it has been really interesting and useful to understand more about Elixir.
I was not sure if it could be the best place to ask questions. If you think that this question is not related to the book please close the issue.
Sometimes when something was wrong when an order is created an error is returned.
it doesn't match with
and the trader is restarted. Great.
But maybe under some circumstances could be useful if the trader stops being restarted, for example, because you need to change some settings.
Does exist some way to tell to the supervisor: stop restarting the trader?
I was thinking about how to match some error cases
but I am not sure about which could be a good way to tell to the supervisor stop restarting the trader.
Or maybe that is not the Elixir way to do things. What do you think?
Thanks in advice for your feedback.
The full log of those types of cases.
Thanks again.