Re: [Mojolicious] Minion Locking problem (deadlock) !

34 views
Skip to first unread message

Sebastian Riedel

unread,
Jun 29, 2017, 3:42:02 AM6/29/17
to mojol...@googlegroups.com
> $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
Message has been deleted

Henry Foolman

unread,
Jun 29, 2017, 7:57:48 AM6/29/17
to Mojolicious
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

sri

unread,
Jun 29, 2017, 8:04:07 AM6/29/17
to Mojolicious
I'm closing this thread since it has become a mess with those deleted messages. Don't do that.

--
sebastian
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages