How to define on spawn handler for Mojo::Server::Prefork?

229 Views Asked by At

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

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

But i dont know, how to insert this hander definitiion in the code of startup method of Mojolicious application. $self->on("spawn"=>sub {}) doesnt work :( And Dumper($self) was not helpful at all: there are no $self->server or $server->prefork ...

Tell me please, how to do it.

Thanks!

1

There are 1 best solutions below

0
On

Although i still dont know how to define handler fired on process "spawn", i can tell that absolutely the same thing can be done by using

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

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

During startup your application is preloaded in the manager process, which does not run an event loop, so you can use "next_tick" in Mojo::IOLoop to run code whenever a new worker process has been forked and its event loop gets started.

Hint: As i see in my real application, Mojo::IOLoop->singleton->next_tick and Mojo::IOLoop->next_tick works absolutely identically, so i dont know what is the difference between them.