Hi Sebastian,
sorry for the mess, but it works.
Thu Jun 29 13:32:21 2017] [debug] Job 7 finished
[Thu Jun 29 13:32:21 2017] [debug] Job 7 with task uuid_job finished



Worker snip:
$job->on(finished => sub {
                         my ($job, $result) = @_;
                         my $id = $job->id;
                         $debugger->debug(sprintf("Job %d finished\n", $id 
));
});



Task Snip:
$job->on(finished => sub {
          my ($job, $result) = @_;
          my $debugger = $app->debug_logger;
          $job->note( uuid => q{xxxxxxxxxxxxxxxxxxxx});
          $debugger->debug(sprintf("Job %d with task %s finished\n", $job->
id, $job->task ));
          $app->minion->unlock(qq{uuid_job_$host});
 });



I tested $job->note.
When equeing, the note is empty but mentioned in the docs as working.
Nevertheless i will move the logic to the worker. It's only a proof of 
concept.
I have to obfuscate certain parameters which i supply via the note 
function. (passwords etc.).

Also i start my workers from a plugin rather than from the commandline.
This is because i have variable queues which will change on demand, so i 
cannot start minion with a predefined queue but adding queues and starting 
workers in a recurring IOLoop.
I store the states and loopids using storable which works perfect.
Of cource i had to set SIGCHLD to ignore and had to change the is_finished 
sub to check the state in the db instead if using waitpid because the pid 
is out of context.
Perhaps there's a change to add queues on demand via a function, than i 
will switch back to the commandline.

Thx.

Hans




Am Donnerstag, 29. Juni 2017 09:42:02 UTC+2 schrieb sri:
>
> > $app->minion->add_task(demo_job => sub { 
> >       my $job = shift; 
> >       my $retval = {}; 
> > 
> >       sleep 1 until $app->minion->lock('demo_job', 7200); 
> > 
> >       $job->on(finished => sub { 
> >           my ($job, $result) = @_; 
> >           my $debugger = $app->debug_logger; 
> >           $debugger->debug(sprintf("Job %d with task %s finished\n", 
> > $job->id, $job->task )); 
> >           $app->minion->unlock('demo_job'); 
> >       }); 
> > 
> >       $job->on(failed => sub { 
> >           my ($job, $err) = @_; 
> >           my $debugger = $app->debug_logger; 
> >           $debugger->debug(sprintf("Job %d with task %s failed %s\n", 
> > $job->id, $job->task, $err )); 
> >           $app->minion->unlock('demo_job'); 
> >       }); 
> > 
> >       $retval->{data}->[0]->{demo_job} = int(rand(1000)); 
> >       $retval->{success} = Cpanel::JSON::XS::true(); 
> >       return $job->finish($retval); 
> >   }); 
>
> You can't use the finished and failed events from inside the task. 
>
> -- 
> Sebastian Riedel 
> http://mojolicio.us 
> http://github.com/kraih 
> http://twitter.com/kraih 
>

-- 
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 https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to