2 # Batch EXecutor 2.0 -- Parallel Execution Using Screen
3 # (c) 2011 Martin Mares <mj@ucw.cz>
16 "q|queue=s" => \$queue_name,
18 Usage: bprun [<options>] [[!]<machine-or-class> ...]
21 -q, --queue=<name> Run jobs in the given queue
24 $ENV{'STY'} or die "Please run me under Screen\n";
25 my @machines = BEX::Config::parse_machine_list(@ARGV ? @ARGV : '*');
26 my $queue = BEX::Queue->new($queue_name);
28 my $fifo_name = $queue->{'Name'} . '/status-fifo';
30 mkfifo $fifo_name, 0700 or die "Cannot create $fifo_name: $!";
31 open FIFO, '+<', $fifo_name or die "Cannot open $fifo_name: $!";
36 while (%running || @machines) {
37 if (@machines && keys %running < $max) {
38 my $mach = shift @machines;
39 $queue->scan($mach) or next;
40 print "$mach: START\n";
41 system 'screen', '-t', $mach, './brun', "--status-fifo=$fifo_name", $mach;
42 !$? or print "$mach: Failed to run!\n";
43 $running{$mach} = 'START';
48 my ($mach, $jid, $stat) = /^! (\S+) (\S+) (\S+)$/;
50 print "ERROR: Received invalid status message <$_>\n";
53 if (!defined $running{$mach}) {
54 print "ERROR: Received status message <$_> for a machine which does not run\n";
57 $running{$mach} = $stat . ($jid eq '-' ? "" : ":$jid");
58 print "$mach: ", $running{$mach}, "\n";
59 if ($stat eq 'DONE') {
60 delete $running{$mach};