[Bio] / FigKernelScripts / run_peg_job_worker.pl Repository:
ViewVC logotype

Diff of /FigKernelScripts/run_peg_job_worker.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Thu Feb 3 17:22:47 2005 UTC revision 1.2, Thu Feb 10 16:57:33 2005 UTC
# Line 8  Line 8 
8    
9  use FIG;  use FIG;
10  use strict;  use strict;
11    use Cluster;
12    
13  my($table) = @ARGV;  my($table) = @ARGV;
14    
# Line 16  Line 17 
17      die "Usage: $0 tablename\n";      die "Usage: $0 tablename\n";
18  }  }
19    
 $table = "pjs_$table";  
   
 my %status_values = (AVAIL => 0,  
                      TAKEN => 1,  
                      DONE => 2  
                      );  
   
   
20  my $fig = new FIG;  my $fig = new FIG;
21  my $fig_dbh = $fig->db_handle;  my $jobmgr = new Cluster::DBJobMgr($fig, $table);
 my $dbh = $fig_dbh->{_dbh};  
 my $dbms = $fig_dbh->{_dbms};  
   
 my $lock_mode;  
   
 if ($dbms eq "mysql")  
 {  
     $lock_mode = "for update";  
 #    $lock_mode = "lock in share mode";  
 }  
22    
23  my $what = 0;  my $what = 0;
24  my $worker = `hostname`;  my $worker = `hostname`;
# Line 44  Line 27 
27    
28  while (1)  while (1)
29  {  {
30      my $work = get_work($worker);      my $work = $jobmgr->get_work($worker);
31      my $output = "finished $work $what\n";      my $output = "finished $work $what\n";
32      $what++;      $what++;
33      work_done($work, $output);      $jobmgr->work_done($work, $output);
34  }  }
35    
 sub get_work  
 {  
     my($worker) = @_;  
     my $work;  
     local $dbh->{AutoCommit} = 0;  
     local $dbh->{RaiseError} = 1;  
   
     eval {  
         my $res = $dbh->selectall_arrayref("select * from $table where status = ? limit 1 $lock_mode", undef,  
                                            $status_values{AVAIL});  
         if (not $res or @$res == 0)  
         {  
             die "No work found\n";  
         }  
   
         my ($peg, $status, $job_taken, $job_finished, $output) = @{$res->[0]};  
         print "Found peg=$peg status=$status job info $job_taken $job_finished\n";  
         $dbh->do("update $table set status = ?, worker = ?, job_taken = now() where peg = ?", undef,  
                  $status_values{TAKEN}, $worker, $peg);  
   
         $dbh->commit();  
         $work = $peg;  
     };  
   
     if ($@)  
     {  
         warn "Error in get_work eval: $@\n";  
         $dbh->rollback();  
         return;  
     }  
     else  
     {  
         return $work;  
     }  
 }  
   
 sub work_done  
 {  
     my($work, $output) = @_;  
   
     local $dbh->{AutoCommit} = 0;  
     local $dbh->{RaiseError} = 1;  
   
     eval {  
         $dbh->do("update $table set status = ?, job_finished = now(), output = ? where peg = ?", undef,  
                  $status_values{DONE}, $output, $work);  
   
         $dbh->commit();  
     };  
   
     if ($@)  
     {  
         warn "Error in work_done eval: $@\n";  
         $dbh->rollback();  
         return;  
     }  
     else  
     {  
         return 1;  
     }  
   
 }  

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3