[erlang-questions] OTP Worker Supervision
Vance Shipley
vances@REDACTED
Wed Oct 15 06:34:07 CEST 2014
On Wed, Oct 15, 2014 at 5:50 AM, Curtis J Schofield (ram9) <curtis@REDACTED>
wrote:
>
> I have been able to create a simple application with a supervisor and spawn
> and link a child process. I feel like I have 'hacked' it and would
> like to hear what the ideomatic way of this is.
>
> init([]) ->
{ok, Pid} = sender_worker:boot_send(),
link(Pid),
Pids = [],
{ok, {{one_for_one, 1, 5}, Pids}}.
The supervisor behaviour encapsulates process creation and linking. All
you need to do is specify the process to create in a child specification:
{Id, StartFunc, Restart, Shutdown, Type, Modules}
So just:
init([]) ->
StartMod = sender_worker,
ChildSpec = {StartMod, {StartMod, boot_send, []}, temporary, 4,
worker, [StartMod]},
{ok, {{one_for_one, 1, 5}, [ChildSpec]}}.
--
-Vance
On Wed, Oct 15, 2014 at 5:50 AM, Curtis J Schofield (ram9) <curtis@REDACTED>
wrote:
> Hi - I'm a beginner and am requesting feedback on some code I wrote.
>
> I haven't been able to deduce 'the otp way' to build a worker process.
> ( this worker generates some garbage and puts it into rabbitmq)
>
> I have been able to create a simple application with a supervisor and spawn
> and link a child process. I feel like I have 'hacked' it and would
> like to hear what the ideomatic way of this is.
>
>
>
> https://github.com/robotarmy/amqresearch/blob/master/send/src/sender_sup.erl
>
>
> https://github.com/robotarmy/amqresearch/blob/master/send/src/sender_worker.erl
>
>
> Feedback on my code would be appreciated.
>
>
> --
> ---
> Modern Yoga vs Traditional Yoga
> http://swamij.com/traditional-yoga.htm#swamirama
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
--
--
-Vance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141015/3e4dd95d/attachment.htm>
More information about the erlang-questions
mailing list