Could you rather explain what the actual problem that you're trying to 
solve is?

Maybe the answer is a cron-job :)

I've implemented some really awful locking mechanism in Convos to only 
start a piece of code in one child. It creates a lock in the Redis database 
to prevent the other children from running the same code. 
https://metacpan.org/source/JHTHORSEN/Convos-0.6/lib/Convos.pm#L323

What is important is that the lock need to be atomic. symlink() 
and $handle->open($name, O_CREAT | O_EXCL) and friends are atomic, but you 
need to be cautious about hypnotoad and "hot reload", or just the fact that 
the child that started the recurring timer might die. 

On Thursday, July 3, 2014 11:46:10 AM UTC+2, Tim wrote:
>
> Hi,
>
> is it possible to start a recurring timer only once when I have multiple 
> workers?
>
> So that I get this output
>
> $ perl test.pl prefork -w 1
>> [Thu Jul  3 11:29:09 2014] [info] Listening at "http://*:3000";.
>> Server available at http://127.0.0.1:3000.
>> [Thu Jul  3 11:29:09 2014] [info] Manager 1836 started.
>> [Thu Jul  3 11:29:09 2014] [debug] Worker 1837 started.
>> [Thu Jul  3 11:29:12 2014] [info] 0
>> [Thu Jul  3 11:29:15 2014] [info] 1
>> [Thu Jul  3 11:29:18 2014] [info] 2
>
>
> instead of
>
> $ perl test.pl prefork -w 4
>> [Thu Jul  3 11:29:28 2014] [info] Listening at "http://*:3000";.
>> Server available at http://127.0.0.1:3000.
>> [Thu Jul  3 11:29:28 2014] [info] Manager 1838 started.
>> [Thu Jul  3 11:29:28 2014] [debug] Worker 1839 started.
>> [Thu Jul  3 11:29:28 2014] [debug] Worker 1840 started.
>> [Thu Jul  3 11:29:28 2014] [debug] Worker 1841 started.
>> [Thu Jul  3 11:29:28 2014] [debug] Worker 1842 started.
>> [Thu Jul  3 11:29:31 2014] [info] 0
>> [Thu Jul  3 11:29:32 2014] [info] 0
>> [Thu Jul  3 11:29:32 2014] [info] 0
>> [Thu Jul  3 11:29:32 2014] [info] 0
>> [Thu Jul  3 11:29:34 2014] [info] 1
>> [Thu Jul  3 11:29:35 2014] [info] 1
>> [Thu Jul  3 11:29:35 2014] [info] 1
>> [Thu Jul  3 11:29:35 2014] [info] 1
>> [Thu Jul  3 11:29:37 2014] [info] 2
>> [Thu Jul  3 11:29:38 2014] [info] 2
>> [Thu Jul  3 11:29:38 2014] [info] 2
>> [Thu Jul  3 11:29:38 2014] [info] 2
>
>
> Code
>
> use Mojolicious::Lite;
>
> get '/' => sub {
>     my $c = shift;
>     $c->render(text => 'test');
> };
>
> sub start_recurring {
>     my $i;
>
>     Mojo::IOLoop->recurring(3 => sub {
>       app->log->info($i++);
>     });
> }
>
> start_recurring;
>
> app->start;
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to