diff options
author | 2008-01-02 04:18:50 +0000 | |
---|---|---|
committer | 2008-01-02 04:18:50 +0000 | |
commit | a086bd72dbbcd8c027c4daafa3a7b9782e509c0f (patch) | |
tree | c4df0445e6b1878beb9f36896d69c00a7ac704b8 | |
parent | fixin up get_jobs a bit. (diff) | |
download | scire-a086bd72dbbcd8c027c4daafa3a7b9782e509c0f.tar.gz scire-a086bd72dbbcd8c027c4daafa3a7b9782e509c0f.tar.bz2 scire-a086bd72dbbcd8c027c4daafa3a7b9782e509c0f.zip |
updating this. minor fixes.
adding job_fetched code.
svn path=/branches/new-fu/; revision=314
-rwxr-xr-x | server/scireserver.pl | 77 |
1 files changed, 58 insertions, 19 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index 9e20154..ba864f5 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -83,9 +83,12 @@ while(<>) { my $job = $args[0]; my $jobfile = get_job($job); print "OK ${jobfile}\n"; + } elsif ($command eq "JOB_FETCHED") { + my $job = $args[0]; + job_fetched($job) and print "OK\n"; } elsif ($command eq "SET_JOB_STATUS") { my ($jobid,$status) = @args; - set_job_status($jobid,$status); + set_job_status($jobid,$status) and print "OK\n"; } else { print "ERROR The command $command is unknown. Please try again.\n"; @@ -228,37 +231,73 @@ sub get_job { #Validate your inputs! my $query = 'SELECT * FROM jobs LEFT JOIN job_conditions on (jobs.jobid) WHERE jobs.jobid = ?'; debug("Query is $query"); -# my $sth = $dbh->prepare($query); -# $sth->execute($jobid); -# my $job = $sth->fetchrow_hashref(); -# my $scriptid = $job->{'script'}; + my $sth = $dbh->prepare($query); + $sth->execute($jobid); + my $job = $sth->fetchrow_hashref(); + my $scriptid = $job->{'script'}; $query = 'SELECT * FROM scripts WHERE scriptid=?'; debug("Query is $query"); -# $sth = $dbh->prepare($query); -# $sth->execute($scriptid); -# $job->{'script'} = $sth->fetchrow_hashref(); + $sth = $dbh->prepare($query); + $sth->execute($scriptid); + $job->{'script'} = $sth->fetchrow_hashref(); -# debug(Dumper($job)); + debug(Dumper($job)); #Write the job w/ all data to a jobfile with the following path /JOBDIR/CLIENT_ID/queue/JOBID.job my $path = "$conf{job_dir}/$client_id/queue"; my $filename = "$path/$jobid.job"; -# unless (-d $path) { -# print "WARNING! $path does not exist...creating\n"; -# mkpath( $path, {verbose => 1, mode => 0660}) -# or die("Couldn't make $path w/ perms 0660: $!"); -# } -# open(FH, ">$filename") or die("Couldn't open $filename: $!"); -# my $xml = pl2xml( $job ); -# print FH $xml."\n"; -# close(FH) or die("Couldn't close $filename : $!"); - debug("OK $filename\n"); + unless (-d $path) { + print "WARNING! $path does not exist...creating\n"; + mkpath( $path, {verbose => 1, mode => 0660}) + or die("Couldn't make $path w/ perms 0660: $!"); + } + open(FH, ">$filename") or die("Couldn't open $filename: $!"); + my $xml = pl2xml( $job ); + print FH $xml."\n"; + close(FH) or die("Couldn't close $filename : $!"); + debug("OK $filename"); return $filename; } +sub job_fetched { + my $jobid = shift; + set_job_status($jobid,'Downloaded') or print "ERROR could not set job status to downloaded.\n"; + + eval { + my $query = 'DELETE FROM jobs_clients WHERE jobid=? AND clientid=?'; + debug("Query is $query"); + my $sth = $dbh->prepare($query); + $sth->execute($jobid,$client_id); + }; + ($@) and print "ERROR Could not get status id: $DBI::errstr\n"; + return 1; +} + sub set_job_status { my ($jobid,$status) = @_; #Validate your inputs! + $jobid =~ /^\d+$/ or die("Invalid jobid $jobid"); + #fixme validate status + my $status_id; + eval { + my $query = 'SELECT statusid FROM jobs_status WHERE statusname = ?'; + debug("Query is $query"); +# $status_id = "4"; #db.conn.GetRow($query) + my $sth = $dbh->prepare($query); + $sth->execute($status); + $status_id = $sth->fetchrow_hashref->{'statusid'}; + }; + ($@) and print "ERROR Could not get status id: $DBI::errstr\n"; + $status_id or print "ERROR Invalid status id $status_id\n"; + + eval { + my $query = 'INSERT INTO job_history (jobid,clientid,statusid) VALUES (?,?,?)'; + debug("Query is $query"); + my $sth = $dbh->prepare($query); + $sth->execute($jobid,$client_id,$status_id); + }; + ($@) and print "ERROR Could not insert into job_history: $DBI::errstr\n"; + return 1; } sub parse_command { |