Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

set functions by new new method

  • Loading branch information...
commit d0eb3fed03bc5d2c8892934faabdeb59122c533c 1 parent e95de0b
Atsushi Kobayashi authored
Showing with 10 additions and 8 deletions.
  1. +3 −1 lib/Jonk.pm
  2. +4 −4 t/multi_process.t
  3. +3 −3 t/worker.t
4 lib/Jonk.pm
View
@@ -17,6 +17,7 @@ sub new {
bless {
dbh => $dbh,
table_name => $opts->{table_name} || 'job',
+ functions => join(', ', map { "'$_'" } @{$opts->{functions}}),
job_find_size => $opts->{job_find_size} || 50,
_errstr => undef,
@@ -25,6 +26,7 @@ sub new {
my ( $sec, $min, $hour, $mday, $mon, $year, undef, undef, undef ) = localtime(time);
return sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
}),
+
}, $class;
}
@@ -147,7 +149,7 @@ sub find_job {
my $sth = $self->{dbh}->prepare_cached(
sprintf('SELECT * FROM %s WHERE func IN (%s) AND grabbed_until <= ? ORDER BY id LIMIT %s',
$self->{table_name},
- join(', ', map { "'$_'" } @{$opts->{functions}}),
+ $self->{functions},
($opts->{job_find_size}||50),
),
);
8 t/multi_process.t
View
@@ -16,8 +16,8 @@ my $dbh = t::Utils->setup;
if ( fork ) {
my $dbh = t::Utils->setup;
- my $jonk = Jonk->new($dbh, {});
- my $job = $jonk->find_job(+{functions => [qw/MyWorker/]});
+ my $jonk = Jonk->new($dbh, {functions => [qw/MyWorker/]});
+ my $job = $jonk->find_job();
is $job->arg, 'arg1';
wait;
@@ -28,8 +28,8 @@ my $dbh = t::Utils->setup;
sleep 1;
- my $jonk = Jonk->new($dbh, {});
- my $job = $jonk->find_job(+{functions => [qw/MyWorker/]});
+ my $jonk = Jonk->new($dbh, {functions => [qw/MyWorker/]});
+ my $job = $jonk->find_job();
is $job->arg, 'arg2';
}
6 t/worker.t
View
@@ -5,12 +5,12 @@ use Jonk;
my $dbh = t::Utils->setup;
subtest 'grab_job' => sub {
- my $client = Jonk->new($dbh, {});
+ my $client = Jonk->new($dbh, {functions => [qw/MyWorker/]});
my $job_id = $client->insert('MyWorker', 'arg');
ok $job_id;
- my $job = $client->find_job(+{functions => [qw/MyWorker/]});
+ my $job = $client->find_job();
is $job->arg, 'arg';
is $job->func, 'MyWorker';
is $job->retry_cnt, 0;
@@ -21,7 +21,7 @@ subtest 'grab_job' => sub {
$job->completed;
- ok not $client->find_job(+{functions => [qw/MyWorker/]});
+ ok not $client->find_job();
};
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.