diff options
author | 2008-01-05 03:02:34 +0000 | |
---|---|---|
committer | 2008-01-05 03:02:34 +0000 | |
commit | ce9d45f4462b255b2981afd4f2ff33d3c93e08fb (patch) | |
tree | 4c5010a0883acf5e08d6b507d3a8c8fb4cc18861 | |
parent | adding job expansion code. (diff) | |
download | scire-ce9d45f4462b255b2981afd4f2ff33d3c93e08fb.tar.gz scire-ce9d45f4462b255b2981afd4f2ff33d3c93e08fb.tar.bz2 scire-ce9d45f4462b255b2981afd4f2ff33d3c93e08fb.zip |
fixed up the expansion w/ one last query.
svn path=/branches/new-fu/; revision=318
-rwxr-xr-x | server/scireserver.pl | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/server/scireserver.pl b/server/scireserver.pl index b50e462..db05d43 100755 --- a/server/scireserver.pl +++ b/server/scireserver.pl @@ -322,6 +322,7 @@ sub expand_jobs { #Searches for the group jobs that the client must be into and does the expansion. my @groups = get_client_groups(); foreach my $groupid (@groups) { + debug("Groupid is $groupid"); my @members = get_group_clients($groupid); eval { my $query = <<'EndOfQuery2'; @@ -329,13 +330,15 @@ SELECT DISTINCT(jobs_clients.jobid) FROM jobs_clients LEFT JOIN job_conditions on (jobs_clients.jobid=job_conditions.jobid) WHERE jobs_clients.groupid = ? AND (job_conditions.deploy_time < now()) -AND (job_conditions.expiration_time > now()) -AND job_conditions.last_run_date < job_conditions.deploy_time +AND ((job_conditions.expiration_time > now()) OR (job_conditions.expiration_time IS NULL)) +AND ((job_conditions.last_run_date < job_conditions.deploy_time) OR (job_conditions.last_run_date IS NULL)) EndOfQuery2 + debug("Query is $query"); my $sth = $dbh->prepare($query); $sth->execute($groupid); - # $dbh->do('LOCK TABLES `jobs_clients` WRITE, `job_conditions` WRITE, `job_history` WRITE'); - while( my $jobid = $sth->fetchrow_hashref->{'jobid'} ) { + $dbh->do('LOCK TABLES `jobs_clients` WRITE, `job_conditions` WRITE, `job_history` WRITE, `jobs_status` WRITE'); + while( my $jobref = $sth->fetchrow_hashref() ) { + my $jobid = $jobref->{'jobid'}; foreach my $member (@members) { $query = 'INSERT INTO jobs_clients (jobid, clientid) VALUES (?,?)'; debug("Query is $query"); @@ -349,10 +352,16 @@ EndOfQuery2 my $sth3 = $dbh->prepare($query); $sth3->execute($jobid); + # One last query to remove the row from jobs_clients so someone else doesn't expand it. + $query = 'DELETE FROM `jobs_clients` WHERE groupid=? AND jobid=?'; + debug("Query is $query"); + my $sth4 = $dbh->prepare($query); + $sth4->execute($groupid,$jobid); } - # $dbh->do('UNLOCK TABLES'); + + $dbh->do('UNLOCK TABLES'); }; - ($@) and print "ERROR Could not expand jobs: $DBI::errstr\n"; + ($@) and print "ERROR Could not expand jobs: $@ $DBI::errstr\n"; return undef; } } @@ -363,6 +372,7 @@ EndOfQuery2 sub get_client_groups { my $query; + my @groups; my $option = 'NO RECURSE'; # If RECURSE it will get all ancestor groups. defaults to only get direct parents. @@ -385,16 +395,16 @@ sub get_client_groups { $sth->execute($client_id); my $groups_ref = $sth->fetchall_arrayref(); # Don't ask me...ask the guys in #perl :P - my @groups = map { @$_ } @$groups_ref; - return @groups; + @groups = map { @$_ } @$groups_ref; }; ($@) and print "ERROR Could not get client groups: $DBI::errstr\n"; - return undef; + return @groups; } sub get_group_clients { #This function gets the members of groups. Returns an array containing those clients, empty otherwise. my $groupid = shift; + my @members; my $query = 'SELECT axo_id FROM gacl_groups_axo_map WHERE group_id = ?'; debug("Query is $query"); eval { @@ -402,9 +412,8 @@ sub get_group_clients { $sth->execute($groupid); my $members_ref = $sth->fetchall_arrayref(); # Don't ask me...ask the guys in #perl :P - my @members = map { @$_ } @$members_ref; - return @members; + @members = map { @$_ } @$members_ref; }; ($@) and print "ERROR Could not get group members: $DBI::errstr\n"; - return undef; + return @members; } |