Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add dequeue_timeout option to run method in Minion::Worker
  • Loading branch information
kraih committed Dec 15, 2017
1 parent 16e7276 commit c988ccf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Changes
@@ -1,5 +1,7 @@

8.08 2017-12-12
8.08 2017-12-15
- Added dequeue_timeout option to run method in Minion::Worker.
- Added -D option to worker command.

8.07 2017-12-11
- Fixed guard method in Minion not to release already expired locks.
Expand Down
3 changes: 3 additions & 0 deletions lib/Minion/Command/minion/worker.pm
Expand Up @@ -13,6 +13,7 @@ sub run {
my $status = $worker->status;
getopt \@args,
'C|command-interval=i' => \$status->{command_interval},
'D|dequeue-timeout=i' => \$status->{dequeue_timeout},
'I|heartbeat-interval=i' => \$status->{heartbeat_interval},
'j|jobs=i' => \$status->{jobs},
'q|queue=s' => \my @queues,
Expand Down Expand Up @@ -53,6 +54,8 @@ Minion::Command::minion::worker - Minion worker command
Options:
-C, --command-interval <seconds> Worker remote control command interval,
defaults to 10
-D, dequeue-timeout <seconds> Maximum amount of time to wait for

This comment has been minimized.

Copy link
@kwakwaversal

kwakwaversal Mar 2, 2018

Contributor

On mobile catching up on old emails so can't do myself - -D option is missing a -- for the long form.

jobs, defaults to 5
-h, --help Show this summary of available options
--home <path> Path to home directory of your
application, defaults to the value of
Expand Down
10 changes: 9 additions & 1 deletion lib/Minion/Worker.pm
Expand Up @@ -55,6 +55,7 @@ sub run {

my $status = $self->status;
$status->{command_interval} //= 10;
$status->{dequeue_timeout} //= 5;
$status->{heartbeat_interval} //= 300;
$status->{jobs} //= 4;
$status->{queues} ||= ['default'];
Expand Down Expand Up @@ -113,10 +114,11 @@ sub _work {
for keys %$jobs;

# Wait if job limit has been reached or worker is stopping
my $timeout = $status->{dequeue_timeout};
if (($status->{jobs} <= keys %$jobs) || $self->{finished}) { sleep 1 }

# Try to get more jobs
elsif (my $job = $self->dequeue(5 => {queues => $status->{queues}})) {
elsif (my $job = $self->dequeue($timeout => {queues => $status->{queues}})) {
$jobs->{my $id = $job->id} = $job->start;
my ($pid, $task) = ($job->pid, $job->task);
}
Expand Down Expand Up @@ -328,6 +330,12 @@ These L</"status"> options are currently available:
Worker remote control command interval, defaults to C<10>.
=item dequeue_timeout
dequeue_timeout => 5
Maximum amount time in seconds to wait for a job, defaults to C<5>.
=item heartbeat_interval
heartbeat_interval => 60
Expand Down
1 change: 1 addition & 0 deletions t/pg_worker.t
Expand Up @@ -37,6 +37,7 @@ is_deeply $minion->job($id)->info->{result}, {just => 'works!'}, 'right result';
# Status
my $status = $worker->status;
is $status->{command_interval}, 10, 'right value';
is $status->{dequeue_timeout}, 5, 'right value';
is $status->{heartbeat_interval}, 300, 'right value';
is $status->{jobs}, 4, 'right value';
is_deeply $status->{queues}, ['default'], 'right structure';
Expand Down

0 comments on commit c988ccf

Please sign in to comment.