How do I define a spawn handler for Mojo :: Server :: Prefork?

I have a simple web application written in perl / Mojolicious and running under hypnosis.

I need to define some kind of handler for the "spawn" event (issued by Mojo :: Server :: Prefork).

But I don’t know how to insert this truth into the Mojolicious method startup code. $self->on("spawn"=>sub {})

does not work :( And it Dumper($self)

didn't help at all: no $ self-> server or $ server-> prefork ...

Please tell me how to do it.

Thank!

+3


source to share


1 answer


Although I still don't know how to define the handler that runs in the "spawn" process, I can say that exactly the same can be done using

Mojo::IOLoop->singleton->next_tick(sub {
  doingSomethingOnProcSpawn()
});

      

As described in the Mojolicious Cookbook ( http://mojolicious.org/perldoc/Mojolicious/Guides/Cookbook#Pre-forking ):



At startup, your application is preloaded by a manager process that does not start an event loop, so you can use next_tick in Mojo :: IOLoop to run code whenever a new workflow unfolds and starts its event loop.

Hint: As I see in my real application, Mojo :: IOLoop-> singleton-> next_tick and Mojo :: IOLoop-> next_tick work exactly the same, so I don't know what the difference is between them.

0


source







All Articles