commit perl-Minion for openSUSE:Factory
Hello community, here is the log from the commit of package perl-Minion for openSUSE:Factory checked in at 2017-08-02 11:28:02 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Minion (Old) and /work/SRC/openSUSE:Factory/.perl-Minion.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "perl-Minion" Wed Aug 2 11:28:02 2017 rev:28 rq:513793 version:7.04 Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Minion/perl-Minion.changes 2017-07-11 08:27:12.587900575 +0200 +++ /work/SRC/openSUSE:Factory/.perl-Minion.new/perl-Minion.changes 2017-08-02 11:28:04.986899277 +0200 @@ -1,0 +2,14 @@ +Wed Aug 2 05:55:12 UTC 2017 - coolo@suse.com + +- updated to 7.04 + see /usr/share/doc/packages/perl-Minion/Changes + + 7.04 2017-08-01 + - Added foreground method to Minion. + - Added id option to dequeue methods in Minion::Worker and + Minion::Backend::Pg. + - Added attempts option to retry and retry_job methods in Minion::Job and + Minion::Backend::Pg. + - Added -f option to job command. + +------------------------------------------------------------------- Old: ---- Minion-7.03.tar.gz New: ---- Minion-7.04.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Minion.spec ++++++ --- /var/tmp/diff_new_pack.MJV4s8/_old 2017-08-02 11:28:05.674802023 +0200 +++ /var/tmp/diff_new_pack.MJV4s8/_new 2017-08-02 11:28:05.682800892 +0200 @@ -17,7 +17,7 @@ Name: perl-Minion -Version: 7.03 +Version: 7.04 Release: 0 %define cpan_name Minion Summary: Job queue ++++++ Minion-7.03.tar.gz -> Minion-7.04.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/Changes new/Minion-7.04/Changes --- old/Minion-7.03/Changes 2017-07-06 23:55:07.000000000 +0200 +++ new/Minion-7.04/Changes 2017-08-01 11:50:57.000000000 +0200 @@ -1,4 +1,12 @@ +7.04 2017-08-01 + - Added foreground method to Minion. + - Added id option to dequeue methods in Minion::Worker and + Minion::Backend::Pg. + - Added attempts option to retry and retry_job methods in Minion::Job and + Minion::Backend::Pg. + - Added -f option to job command. + 7.03 2017-07-06 - Updated Mojo::Pg requirement to 4.0. - Improved Minion::Backend::Pg to support sharing the database connection diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/MANIFEST.SKIP new/Minion-7.04/MANIFEST.SKIP --- old/Minion-7.03/MANIFEST.SKIP 2017-06-24 15:01:28.000000000 +0200 +++ new/Minion-7.04/MANIFEST.SKIP 2017-07-28 12:05:57.000000000 +0200 @@ -5,3 +5,4 @@ ^MYMETA\. ^blib ^pm_to_blib +\B\.DS_Store diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/META.json new/Minion-7.04/META.json --- old/Minion-7.03/META.json 2017-07-06 23:56:48.000000000 +0200 +++ new/Minion-7.04/META.json 2017-08-01 15:19:43.000000000 +0200 @@ -54,6 +54,6 @@ }, "x_IRC" : "irc://irc.perl.org/#mojo" }, - "version" : "7.03", + "version" : "7.04", "x_serialization_backend" : "JSON::PP version 2.94" } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/META.yml new/Minion-7.04/META.yml --- old/Minion-7.03/META.yml 2017-07-06 23:56:48.000000000 +0200 +++ new/Minion-7.04/META.yml 2017-08-01 15:19:43.000000000 +0200 @@ -27,5 +27,5 @@ homepage: http://mojolicious.org license: http://www.opensource.org/licenses/artistic-license-2.0 repository: https://github.com/kraih/minion.git -version: '7.03' +version: '7.04' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Backend/Pg.pm new/Minion-7.04/lib/Minion/Backend/Pg.pm --- old/Minion-7.03/lib/Minion/Backend/Pg.pm 2017-07-06 23:53:19.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Backend/Pg.pm 2017-08-01 11:44:20.000000000 +0200 @@ -180,12 +180,13 @@ return !!$self->pg->db->query( "update minion_jobs - set delayed = (now() + (interval '1 second' * ?)), + set attempts = coalesce(?, attempts), + delayed = (now() + (interval '1 second' * ?)), priority = coalesce(?, priority), queue = coalesce(?, queue), retried = now(), retries = retries + 1, state = 'inactive' where id = ? and retries = ? - returning 1", $options->{delay} // 0, @$options{qw(priority queue)}, $id, - $retries + returning 1", $options->{attempts}, $options->{delay} // 0, + @$options{qw(priority queue)}, $id, $retries )->rows; } @@ -242,16 +243,17 @@ set started = now(), state = 'active', worker = ? where id = ( select id from minion_jobs as j - where delayed <= now() and (parents = '{}' or not exists ( - select 1 from minion_jobs - where id = any (j.parents) - and state in ('inactive', 'active', 'failed') - )) and queue = any (?) and state = 'inactive' and task = any (?) + where delayed <= now() and id = coalesce(?, id) + and (parents = '{}' or not exists ( + select 1 from minion_jobs + where id = any (j.parents) + and state in ('inactive', 'active', 'failed') + )) and queue = any (?) and state = 'inactive' and task = any (?) order by priority desc, id limit 1 for update skip locked ) - returning id, args, retries, task", $id, + returning id, args, retries, task", $id, $options->{id}, $options->{queues} || ['default'], [keys %{$self->minion->tasks}] )->expand->hash; } @@ -331,6 +333,12 @@ =over 2 +=item id + + id => '10023' + +Dequeue a specific job. + =item queues queues => ['important'] @@ -689,6 +697,12 @@ =over 2 +=item attempts + + attempts => 25 + +Number of times performing this job will be attempted. + =item delay delay => 10 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Backend.pm new/Minion-7.04/lib/Minion/Backend.pm --- old/Minion-7.03/lib/Minion/Backend.pm 2017-06-25 19:45:15.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Backend.pm 2017-08-01 11:44:46.000000000 +0200 @@ -110,6 +110,12 @@ =over 2 +=item id + + id => '10023' + +Dequeue a specific job. + =item queues queues => ['important'] @@ -468,6 +474,12 @@ =over 2 +=item attempts + + attempts => 25 + +Number of times performing this job will be attempted. + =item delay delay => 10 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Command/minion/job.pm new/Minion-7.04/lib/Minion/Command/minion/job.pm --- old/Minion-7.03/lib/Minion/Command/minion/job.pm 2017-06-24 15:01:28.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Command/minion/job.pm 2017-08-01 10:58:41.000000000 +0200 @@ -18,6 +18,7 @@ 'b|broadcast=s' => (\my $command), 'd|delay=i' => \$options->{delay}, 'e|enqueue=s' => \my $enqueue, + 'f|foreground' => \my $foreground, 'l|limit=i' => \(my $limit = 100), 'o|offset=i' => \(my $offset = 0), 'P|parent=s' => ($options->{parents} = []), @@ -31,11 +32,11 @@ 'w|workers' => \my $workers; # Worker remote control command - return $self->app->minion->backend->broadcast($command, $args, \@args) - if $command; + my $minion = $self->app->minion; + return $minion->backend->broadcast($command, $args, \@args) if $command; # Enqueue - return say $self->app->minion->enqueue($enqueue, $args, $options) if $enqueue; + return say $minion->enqueue($enqueue, $args, $options) if $enqueue; # Show stats return $self->_stats if $stats; @@ -45,7 +46,7 @@ return $id ? $self->_worker($id) : $self->_list_workers($offset, $limit) if $workers; return $self->_list_jobs($offset, $limit, $options) unless defined $id; - die "Job does not exist.\n" unless my $job = $self->app->minion->job($id); + die "Job does not exist.\n" unless my $job = $minion->job($id); # Remove job return $job->remove || die "Job is active.\n" if $remove; @@ -53,6 +54,9 @@ # Retry job return $job->retry($options) || die "Job is active.\n" if $retry; + # Perform job in foreground + return $minion->foreground($id) || die "Job is not ready.\n" if $foreground; + # Job info print dumper _datetime($job->info); } @@ -100,6 +104,7 @@ ./myapp.pl minion job -w ./myapp.pl minion job -w 23 ./myapp.pl minion job -s + ./myapp.pl minion job -f 10023 ./myapp.pl minion job -q important -t foo -S inactive ./myapp.pl minion job -e foo -a '[23, "bar"]' ./myapp.pl minion job -e foo -P 10023 -P 10024 -p 5 -q important @@ -117,6 +122,9 @@ workers -d, --delay <seconds> Delay new job for this many seconds -e, --enqueue <task> New job to be enqueued + -f, --foreground Retry job in "minion_foreground" queue and + perform it right away in the foreground (very + useful for debugging) -h, --help Show this summary of available options --home <path> Path to home directory of your application, defaults to the value of MOJO_HOME or diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Command/minion/worker.pm new/Minion-7.04/lib/Minion/Command/minion/worker.pm --- old/Minion-7.03/lib/Minion/Command/minion/worker.pm 2017-07-06 00:22:50.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Command/minion/worker.pm 2017-07-27 23:12:21.000000000 +0200 @@ -37,10 +37,12 @@ stop => sub { $self->{jobs}{$_[1]}->stop if $self->{jobs}{$_[1] // ''} }); # Log fatal errors - $app->log->debug("Worker $$ started"); + my $log = $app->log; + $log->info("Worker $$ started"); eval { $self->_work until $self->{finished} && !keys %{$self->{jobs}}; 1 } - or $app->log->fatal("Worker error: $@"); + or $log->fatal("Worker error: $@"); $worker->unregister; + $log->info("Worker $$ stopped"); } sub _work { @@ -59,9 +61,10 @@ if ($self->{last_command} + $status->{command_interval}) < steady_time; # Repair in regular intervals (randomize to avoid congestion) + my $app = $self->app; + my $log = $app->log; if (($self->{last_repair} + $status->{repair_interval}) < steady_time) { - my $app = $self->app; - $app->log->debug('Checking worker registry and job queue'); + $log->debug('Checking worker registry and job queue'); $app->minion->repair; $self->{last_repair} = steady_time; } @@ -78,8 +81,7 @@ elsif (my $job = $worker->dequeue(5 => {queues => $status->{queues}})) { $jobs->{my $id = $job->id} = $job->start; my ($pid, $task) = ($job->pid, $job->task); - $self->app->log->debug( - qq{Performing job "$id" with task "$task" in process $pid}); + $log->debug(qq{Process $pid is performing job "$id" with task "$task"}); } } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Job.pm new/Minion-7.04/lib/Minion/Job.pm --- old/Minion-7.03/lib/Minion/Job.pm 2017-06-25 20:14:47.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Job.pm 2017-08-01 11:46:27.000000000 +0200 @@ -55,19 +55,27 @@ return $self->emit(spawn => $pid) if $self->{pid} = $pid; # Child - eval { + $self->_run; + POSIX::_exit(0); +} + +sub stop { kill 'KILL', shift->{pid} } + +sub _run { + my $self = shift; + + return 1 if eval { # Reset event loop Mojo::IOLoop->reset; $self->minion->tasks->{$self->emit('start')->task}->($self, @{$self->args}); 1; - } or $self->fail($@); - POSIX::_exit(0); + }; + $self->fail($@); + return undef; } -sub stop { kill 'KILL', shift->{pid} } - 1; =encoding utf8 @@ -397,6 +405,12 @@ =over 2 +=item attempts + + attempts => 25 + +Number of times performing this job will be attempted. + =item delay delay => 10 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion/Worker.pm new/Minion-7.04/lib/Minion/Worker.pm --- old/Minion-7.03/lib/Minion/Worker.pm 2017-06-24 15:01:28.000000000 +0200 +++ new/Minion-7.04/lib/Minion/Worker.pm 2017-08-01 01:25:58.000000000 +0200 @@ -149,6 +149,12 @@ =over 2 +=item id + + id => '10023' + +Dequeue a specific job. + =item queues queues => ['important'] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/lib/Minion.pm new/Minion-7.04/lib/Minion.pm --- old/Minion-7.03/lib/Minion.pm 2017-07-06 20:08:57.000000000 +0200 +++ new/Minion-7.04/lib/Minion.pm 2017-08-01 15:18:17.000000000 +0200 @@ -16,7 +16,7 @@ has remove_after => 172800; has tasks => sub { {} }; -our $VERSION = '7.03'; +our $VERSION = '7.04'; sub add_task { ($_[0]->tasks->{$_[1]} = $_[2]) and return $_[0] } @@ -27,6 +27,21 @@ return $id; } +sub foreground { + my ($self, $id) = @_; + + return undef unless my $job = $self->job($id); + return undef + unless $job->retry({attempts => 1, queue => 'minion_foreground'}); + + my $worker = $self->worker->register; + $job = $worker->dequeue(0 => {id => $id, queues => ['minion_foreground']}); + $job->_run and $job->finish if $job; + $worker->unregister; + + return !!$job; +} + sub job { my ($self, $id) = @_; @@ -394,6 +409,13 @@ =back +=head2 foreground + + my $bool = $minion->foreground($id); + +Retry job in C<minion_foreground> queue, then perform it right away with a +temporary worker in this process, very useful for debugging. + =head2 job my $job = $minion->job($id); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Minion-7.03/t/pg.t new/Minion-7.04/t/pg.t --- old/Minion-7.03/t/pg.t 2017-06-25 19:45:35.000000000 +0200 +++ new/Minion-7.04/t/pg.t 2017-08-01 11:56:53.000000000 +0200 @@ -562,19 +562,29 @@ is $job->id, $id, 'right id'; is $job->retries, 0, 'job has not been retried'; $job->perform; -is $job->info->{attempts}, 2, 'job will be attempted twice'; -is $job->info->{state}, 'inactive', 'right state'; -is $job->info->{result}, 'Non-zero exit status (1)', 'right result'; -ok $job->info->{retried} < $job->info->{delayed}, 'delayed timestamp'; +$info = $job->info; +is $info->{attempts}, 2, 'job will be attempted twice'; +is $info->{state}, 'inactive', 'right state'; +is $info->{result}, 'Non-zero exit status (1)', 'right result'; +ok $info->{retried} < $job->info->{delayed}, 'delayed timestamp'; $minion->backend->pg->db->query( 'update minion_jobs set delayed = now() where id = ?', $id); $job = $worker->register->dequeue(0); is $job->id, $id, 'right id'; is $job->retries, 1, 'job has been retried once'; $job->perform; -is $job->info->{attempts}, 2, 'job will be attempted twice'; -is $job->info->{state}, 'failed', 'right state'; -is $job->info->{result}, 'Non-zero exit status (1)', 'right result'; +$info = $job->info; +is $info->{attempts}, 2, 'job will be attempted twice'; +is $info->{state}, 'failed', 'right state'; +is $info->{result}, 'Non-zero exit status (1)', 'right result'; +ok $job->retry({attempts => 3}), 'job retried'; +$job = $worker->register->dequeue(0); +is $job->id, $id, 'right id'; +$job->perform; +$info = $job->info; +is $info->{attempts}, 3, 'job will be attempted three times'; +is $info->{state}, 'failed', 'right state'; +is $info->{result}, 'Non-zero exit status (1)', 'right result'; $worker->unregister; # Multiple attempts during maintenance @@ -701,6 +711,40 @@ ok $job->finish, 'job finished'; $worker->unregister; +# Foreground +$id = $minion->enqueue(test => [] => {attempts => 2}); +$id2 = $minion->enqueue('test'); +$id3 = $minion->enqueue(test => [] => {parents => [$id, $id2]}); +ok !$minion->foreground($id3 + 1), 'job does not exist'; +ok !$minion->foreground($id3), 'job is not ready yet'; +$info = $minion->job($id)->info; +is $info->{attempts}, 2, 'job will be attempted twice'; +is $info->{state}, 'inactive', 'right state'; +is $info->{queue}, 'default', 'right queue'; +ok $minion->foreground($id), 'performed first job'; +$info = $minion->job($id)->info; +is $info->{attempts}, 1, 'job will be attempted once'; +is $info->{retries}, 1, 'job has been retried'; +is $info->{state}, 'finished', 'right state'; +is $info->{queue}, 'minion_foreground', 'right queue'; +ok $minion->foreground($id2), 'performed second job'; +$info = $minion->job($id2)->info; +is $info->{retries}, 1, 'job has been retried'; +is $info->{state}, 'finished', 'right state'; +is $info->{queue}, 'minion_foreground', 'right queue'; +ok $minion->foreground($id3), 'performed third job'; +$info = $minion->job($id3)->info; +is $info->{retries}, 2, 'job has been retried twice'; +is $info->{state}, 'finished', 'right state'; +is $info->{queue}, 'minion_foreground', 'right queue'; +$id = $minion->enqueue('fail'); +$minion->foreground($id); +$info = $minion->job($id)->info; +is $info->{retries}, 1, 'job has been retried'; +is $info->{state}, 'failed', 'right state'; +is $info->{queue}, 'minion_foreground', 'right queue'; +is $info->{result}, "Intentional failure!\n", 'right result'; + # Worker remote control commands $worker = $minion->worker->register->process_commands; $worker2 = $minion->worker->register;
participants (1)
-
root@hilbert.suse.de