سؤال

What is the most conventional way of implementing a process, which only should do its work and exit?

In my case these workers are supervised by simple_one_for_one supervisor. I was searching around, but haven't found anything better than just spawn_link:

work(Args) ->
{ok, spawn_link(fun() ->
    ... do_the_necessary_work ...
end)}.

Nevertheless, this way doesn't seem to be the good OTP design.

Any ideas?

هل كانت مفيدة؟

المحلول

That's actually a decent way, just make sure you are using proc_lib:spawn_link(...) instead of erlang:spawn_link(...) (to store ancestors for supervision tree traversing, and for more verbose error logs).

And, of course, you might want to make restart strategy for all workers set to temporary or transient, depending on what you are going to do in case of worker failure (restart the worker and attempt to do the job once again or discard the job in case of any failures).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top