[erlang-questions] OTP Worker Supervision

Curtis J Schofield (ram9) curtis@REDACTED
Wed Oct 15 17:32:16 CEST 2014


Thank you Vance. That does indeed work - I think I want 'permanent' so
that the worker comes back if the application crashes - is it as
simple as that?

My question about ChildSpec is about 'Module' and the erlang docs.

>From the erlang docs:
"Modules is used by the release handler during code replacement to
determine which processes are using a certain module. As a rule of
thumb Modules should be a list with one element [Module], where Module
is the callback module, if the child process is a supervisor,
gen_server or gen_fsm."

My 'sender_worker' is just a module - it is not a supervisor,
gen_server or gen_fsm. Is there some specific interface that the
module function 'boot_send' needs to conform to - or is returning {ok,
Pid} what it needs to do?



On Tue, Oct 14, 2014 at 9:34 PM, Vance Shipley <vances@REDACTED> wrote:
>
> 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



-- 
---
Modern Yoga vs Traditional Yoga
http://swamij.com/traditional-yoga.htm#swamirama



More information about the erlang-questions mailing list