Changeset 124

Show
Ignore:
Timestamp:
06/20/07 21:12:09 (1 year ago)
Author:
btrott
Message:

Set insert_time of new jobs to the current server time, when inserting
a job. Added tests for it.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGES

    r122 r124  
     11.05 
     2 
     3    - Set TheSchwartz::Job::insert_time to current server time when 
     4      inserting a new job. 
     5 
    161.04 (2007-05-22) 
    27 
  • trunk/lib/TheSchwartz.pm

    r122 r124  
    55use fields qw( databases retry_seconds dead_dsns retry_at funcmap_cache verbose all_abilities current_abilities current_job cached_drivers driver_cache_expiration ); 
    66 
    7 our $VERSION = "1.04"; 
     7our $VERSION = "1.05"; 
    88 
    99use Carp qw( croak ); 
     
    269269} 
    270270 
     271sub get_server_time { 
     272    my TheSchwartz $client = shift; 
     273    my($driver) = @_; 
     274    my $unixtime_sql = $driver->dbd->sql_for_unixtime; 
     275    return $driver->rw_handle->selectrow_array("SELECT $unixtime_sql"); 
     276} 
     277 
    271278sub _grab_a_job { 
    272279    my TheSchwartz $client = shift; 
     
    287294        my $old_grabbed_until = $job->grabbed_until; 
    288295 
    289         my $unixtime_sql = $driver->dbd->sql_for_unixtime; 
    290         my $server_time = $driver->rw_handle->selectrow_array("SELECT $unixtime_sql") 
     296        my $server_time = $client->get_server_time($driver) 
    291297            or die "expected a server time"; 
    292298 
     
    329335        ## on the hashed DSN. Also: this might fail, if the database is dead. 
    330336        $job->funcid( $client->funcname_to_id($driver, $hashdsn, $job->funcname) ); 
     337 
     338        my $time = $client->get_server_time($driver) 
     339            or die "Can't get server time"; 
     340        $job->insert_time($time); 
    331341 
    332342        ## Now, insert the job. This also might fail. 
     
    791801before looking again. 
    792802 
     803=head2 C<$client-E<gt>work_on($handle)> 
     804 
     805Given a job handle (a scalar string) I<$handle>, runs the job, then returns. 
     806 
    793807=head2 C<$client-E<gt>find_job_for_workers( [$abilities] )> 
    794808 
     
    811825job databases. 
    812826 
     827=head2 C<$client-E<gt>get_server_time( $driver )> 
     828 
     829Given an open driver I<$driver> to a database, gets the current server time from the database. 
     830 
    813831=head1 COPYRIGHT, LICENSE & WARRANTY 
    814832 
  • trunk/t/api.t

    r122 r124  
    88 
    99use TheSchwartz; 
    10 use Test::More tests => 80
     10use Test::More tests => 84
    1111 
    12 run_tests(40, sub { 
     12run_tests(42, sub { 
    1313    foreach my $pfx ("", "testprefix_") { 
    1414 
     
    3131        isa_ok $job, 'TheSchwartz::Job'; 
    3232        is $job->funcname, 'feedmajor', 'handle->job gives us the right job'; 
     33        cmp_ok $job->insert_time, '>', 0, 'insert_time is non-zero'; 
    3334 
    3435        # getting a handle object back