Skip to content

Commit

Permalink
enqueue time is unixtime!
Browse files Browse the repository at this point in the history
  • Loading branch information
nekokak committed Feb 8, 2011
1 parent 9760cf8 commit 039e4aa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
15 changes: 5 additions & 10 deletions lib/Jonk.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ sub new {

_errstr => undef,

insert_time_callback => ($opts->{insert_time_callback}||sub{
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);
}),

insert_query => sprintf(
'INSERT INTO %s (func, arg, enqueue_time, grabbed_until, run_after, retry_cnt, priority) VALUES (?,?,?,0,?,0,?)'
,$table_name
Expand Down Expand Up @@ -105,11 +100,11 @@ sub insert {
local $self->{dbh}->{RaiseError} = 1;
local $self->{dbh}->{PrintError} = 0;

my $serializer = $self->{functions}->{$func}->{serializer} || sub {$_[0]};
my $serializer = $self->{functions}->{$func}->{serializer} ||= sub {$_[0]};
my $sth = $self->{dbh}->prepare_cached($self->{insert_query});
$sth->bind_param(1, $func);
$sth->bind_param(2, $serializer->($arg), _bind_param_attr($self->{driver}));
$sth->bind_param(3, $self->{insert_time_callback}->());
$sth->bind_param(3, time());
$sth->bind_param(4, $opt->{run_after}||0);
$sth->bind_param(5, $opt->{priority} ||0);
$sth->execute();
Expand Down Expand Up @@ -395,7 +390,7 @@ get most recent error infomation.
id int(10) UNSIGNED NOT NULL auto_increment,
func varchar(255) NOT NULL,
arg MEDIUMBLOB,
enqueue_time DATETIME NOT NULL,
enqueue_time INTEGER UNSIGNED,
grabbed_until int(10) UNSIGNED NOT NULL,
run_after int(10) UNSIGNED NOT NULL DEFAULT 0,
retry_cnt int(10) UNSIGNED NOT NULL DEFAULT 0,
Expand All @@ -409,7 +404,7 @@ get most recent error infomation.
id INTEGER PRIMARY KEY ,
func text,
arg text,
enqueue_time text,
enqueue_time INTEGER UNSIGNED,
grabbed_until INTEGER UNSIGNED NOT NULL,
run_after INTEGER UNSIGNED NOT NULL DEFAULT 0,
retry_cnt INTEGER UNSIGNED NOT NULL DEFAULT 0,
Expand All @@ -422,7 +417,7 @@ get most recent error infomation.
id SERIAL PRIMARY KEY,
func TEXT NOT NULL,
arg BYTEA,
enqueue_time TIMESTAMP NOT NULL,
enqueue_time INTEGER,
grabbed_until INTEGER NOT NULL,
run_after INTEGER NOT NULL DEFAULT 0,
retry_cnt INTEGER NOT NULL DEFAULT 0,
Expand Down
21 changes: 0 additions & 21 deletions t/client.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,6 @@ subtest 'insert' => sub {
ok not $jonk->errstr;
};

subtest 'insert / and insert_time_callback' => sub {
my $time;
my $jonk = Jonk->new($dbh,+{insert_time_callback => sub {
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time);
$time = sprintf('%04d-%02d-%02d %02d:%02d:%02d', $year + 1900, $mon + 1, $mday, $hour, $min, $sec);
}});

my $job_id = $jonk->insert('MyWorker', 'arg');
ok $job_id;

my $sth = $dbh->prepare('SELECT * FROM job WHERE id = ?');
$sth->execute($job_id);
my $row = $sth->fetchrow_hashref;

is $row->{arg}, 'arg';
is $row->{func}, 'MyWorker';
is $row->{enqueue_time}, $time;

ok not $jonk->errstr;
};

subtest 'error handling' => sub {
my $jonk = Jonk->new($dbh, +{table_name => 'jonk_job'});

Expand Down

0 comments on commit 039e4aa

Please sign in to comment.