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

瀏覽次數:34 次
跳到第一則未讀訊息

Sebastian Riedel

未讀,
2017年6月29日 凌晨3:42:022017/6/29
收件者: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
訊息已遭刪除

Henry Foolman

未讀,
2017年6月29日 清晨7:57:482017/6/29
收件者: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

未讀,
2017年6月29日 上午8:04:072017/6/29
收件者:Mojolicious
I'm closing this thread since it has become a mess with those deleted messages. Don't do that.

--
sebastian
回覆所有人
回覆作者
轉寄
這個會話群組已被鎖定
你無法在已鎖定的會話群組內回覆及執行操作。
0 則新訊息