diff options
author | 2008-01-07 03:38:31 +0000 | |
---|---|---|
committer | 2008-01-07 03:38:31 +0000 | |
commit | 814df59ab6038e7c36b1fb2de76cabf9a23cb7c8 (patch) | |
tree | b8f1709d6644486df190794b79945be8d650d3c9 | |
parent | handle a non-zero exitcode from the communicator (diff) | |
download | scire-814df59ab6038e7c36b1fb2de76cabf9a23cb7c8.tar.gz scire-814df59ab6038e7c36b1fb2de76cabf9a23cb7c8.tar.bz2 scire-814df59ab6038e7c36b1fb2de76cabf9a23cb7c8.zip |
attempt to add the recurring job rescheduling into the server.
not tested.
svn path=/branches/new-fu/; revision=343
-rwxr-xr-x | server/scireserver.pl | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index 68d6fe9..f577f1e 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -8,6 +8,8 @@ use DBI; use Data::Dumper; use Digest::MD5 qw(md5 md5_hex ); use File::Path; +use Schedule::Cron::Events; + $| = 1; $Data::Dumper::Purity = 1; @@ -368,6 +370,13 @@ EndOfQuery2 sub mark_job_as_failed { my ($jobid,$id_of_client) = @_; + + #First off, update the pending count and failed count with the result. + eval { + my $query = 'UPDATE jobs SET pending=pending-1, failed=failed+1 WHERE jobid=?'; + run_query($query); + }; + ($@) and print "ERROR Could not update pending count: $@ $DBI::errstr\n"; } sub mark_job_as_completed { @@ -380,9 +389,35 @@ sub mark_job_as_completed { #First off, update the pending count now that we've finished. eval { $query = 'UPDATE jobs SET pending=pending-1 WHERE jobid=?'; - debug("Query is $query"); + run_query($query,$jobid); }; ($@) and print "ERROR Could not update pending count: $@ $DBI::errstr\n"; + + #Now get the pending count and run_schedule. + eval { + $query = 'SELECT pending,run_schedule,expiration_time,deploy_time FROM jobs WHERE jobid=?'; + my $sth = run_query($query,$jobid); + my $rowref = $sth->fetchrow_hashref(); + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + my $datetime = sprintf "%4d-%02d-%02d %02d:%02d:%02d\n",$year+1900,$mon+1,$mday,$hour,$min,$sec; + if ($rowref->{'run_schedule'} and ($rowref->{'pending'} == 0) and ( $rowref->{'expiration_time'} > $datetime)) { + #Determine the next run time. + my $cron = new Schedule::Cron::Events( $rowref->{'run_schedule'}, Date => [ ( localtime(time()) )[0..5] ] ); + my ($sec, $min, $hour, $day, $month, $year) = $cron->nextEvent; + printf("Event will start next at %2d:%02d:%02d on %d %s, %d\n", $hour, $min, $sec, $day, $month, ($year+1900)); + + #Get the groups and clients from the recurring_jobs_clients table. + $query = 'SELECT clientid,groupid FROM recurring_jobs_clients WHERE jobid=?'; + my $sth2 = run_query($query,$jobid); + while( my $recrow_ref = $sth2->fetchrow_hashref() ) { + $query = 'INSERT INTO jobs_clients (jobid,clientid,groupid) VALUES (?,?,?)'; + run_query($query,$jobid,$recrow_ref->{'clientid'},$recrow_ref->{'groupid'}); + } + } + + }; + ($@) and print "ERROR Could not get run_schedule and pending count: $@ $DBI::errstr\n"; + } sub process_jobfile { |