[erlang-questions] OTP Worker Supervision

Graham Hay grahamrhay@REDACTED
Wed Oct 15 18:08:54 CEST 2014


Sorry, that wasn't meant to be a put down. It contains the answer to your
other question though (what "permanent" means).

As for the second question, try it and see :)

On 15 October 2014 17:04, Curtis J Schofield (ram9) <curtis@REDACTED> wrote:

> Thank you Graham.
>
> I have read this page - in the example it uses a 'gen_server' for the
> module - which still leaves me with my above question. I'm not sure
> what you are trying to communicate with this webpage.
>
> Learn You Some Erlang has been a helpful resource.
>
> For example from the page:
> "StartFunc is a tuple that tells how to start the supervisor. It's the
> standard {M,F,A} format we've used a few times already. Note that it
> is very important that the starting function here is OTP-compliant and
> links to its caller when executed (hint: use gen_*:start_link()
> wrapped in your own module, all the time)."
>
>
> for example
>
> https://github.com/robotarmy/amqresearch/blob/master/send/src/sender_worker.erl
>
> What I am trying to learn is how to make sure that my function 'F'
> boot_send() is correctly compliant, or my module is correctly
> compliant.
>
>
> On Wed, Oct 15, 2014 at 8:47 AM, Graham Hay <grahamrhay@REDACTED> wrote:
> > http://learnyousomeerlang.com/supervisors
> >
> > On 15 October 2014 16:32, Curtis J Schofield (ram9) <curtis@REDACTED>
> wrote:
> >>
> >> 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
> >> _______________________________________________
> >> erlang-questions mailing list
> >> erlang-questions@REDACTED
> >> http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
>
>
>
> --
> ---
> Modern Yoga vs Traditional Yoga
> http://swamij.com/traditional-yoga.htm#swamirama
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20141015/a341fcf9/attachment.htm>


More information about the erlang-questions mailing list