Changeset 38 for trunk/oarutils


Ignore:
Timestamp:
Dec 4, 2011, 11:04:19 PM (12 years ago)
Author:
g7moreau
Message:
  • Add logfile and restart fonctionality
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/oarutils/oar-parexec

    r37 r38  
    1717
    1818my $file = '';
     19my $logfile = '';
    1920my $verbose;
    2021my $job_np = 1;
     
    2728Getopt::Long::GetOptions(
    2829   'file=s'     => \$file,
     30   'logfile=s'  => \$logfile,
    2931   'verbose'    => \$verbose,
    3032   'help'       => \$help,
     
    3840pod2usage( -verbose => 2 ) if not -e $file;
    3941
     42my %state;
     43my $log_h = IO::File->new();
     44if (-e $logfile) {
     45        $log_h->open("< $logfile")
     46         or die "can't read log file: $!";
     47   while (<$log_h>) {
     48                $state{$1} = 'start' if m/^start\sjob\s(\d+)/;
     49                $state{$1} = 'end'   if m/^end\sjob\s(\d+)/;
     50           }
     51   $log_h->close();
     52   }
     53if ($logfile) {
     54   $log_h->open(">> $logfile")
     55         or die "can't open log file: $!";
     56   $log_h = unblock $log_h;
     57   }
     58
    4059my @job = ();
    4160open( JOB_LIST, '<', "$file" ) or die "can't open $file: $!";
     
    87106async {
    88107   for my $job (@job) {
     108      $job_num++;
     109                if (exists $state{$job_num} and $state{$job_num} eq 'end') {
     110                        delete $state{$job_num};
     111                        cede;
     112                        next;
     113                   }
     114                if (exists $state{$job_num} and $state{$job_num} eq 'start') {
     115                        print "warning: job $job_num was not finished, relaunching...\n" if $verbose;
     116                   }           
     117
    89118      my $job_ressource = $ressources->get;
    90 
    91       $job_num++;
    92119
    93120      my ($node_connect) = split ',', $job_ressource;
     
    101128      $scheduled{$job_pid} = { fh => $fh, node_connect => $node_connect, ressource => $job_ressource, num => $job_num };
    102129
     130      $log_h->printf("start job %5i at %s\n", $job_num, time) if $logfile;
    103131      printf "start job %5i / %5i at %s on node %s\n",
    104132         $job_num, $job_pid, time, $job_ressource
     
    133161      for my $job_pid ( keys %scheduled ) {
    134162         if ( waitpid( $job_pid, WNOHANG ) ) {
     163            $log_h->printf("end job %5i at %s\n", $job_num, time) if $logfile;
    135164            printf "end   job %5i / %5i at %s on node %s\n",
    136165               $scheduled{$job_pid}->{num},
     
    155184$finished->wait;
    156185
     186$log_h->close if $logfile;
     187
    157188__END__
    158189
Note: See TracChangeset for help on using the changeset viewer.