bin/waitjobs

filter: Statementstmt 61.9% 39 / 63 Branchbran 16.6% 2 / 12 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 83.3% 10 / 12 Podpod n/a totaltotal 54.7% 52 / 95 CC 1 SCAR 1.5
CC
1
Cov
52%
__ANON__
2.0
usage
2.0
BEGIN
1.0
CRAP 1.2
« bin/printslurm ↑ Summary bin/printpath »
1 #!/usr/bin/env perl
2 #ABSTRACT: Wait for selected jobs to exit the queue
3 #PODNAME: waitjobs
4  
5 1 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use FindBin qw($RealBin);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Term::ANSIColor qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶if (-e "$RealBin/../dist.ini") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$main::RealBin/../dist.ini") 1 0 1
12 1 ▶ say STDERR "[dev mode] Using local lib" if ($ENV{"DEBUG"});
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG"} 0 1 1
13 1 ▶ use lib "$RealBin/../lib";
Subroutine BEGIN: called CC=1 SCAR=0.0
14 }
15 1 ▶use NBI::Slurm;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use NBI::Queue;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 $Data::Dumper::Sortkeys = 1;
18  
19 1 my $opt_user = $ENV{USER};
20 1 my $opt_name = '.+';
21 1 my $opt_status = '';
22 1 my $opt_verbose_bool = 0;
23 1 my $opt_debug_bool = 0;
24 1 my $refresh_time = 20;
25 # Check if this script is running as a job, in case save the job id
26 1 ▶my $self_job_id = $ENV{SLURM_JOB_ID} // undef;
Condition50%1/2
$ENV{"SLURM_JOB_ID"} // undef
l!l
01
MC/DC0%0/1
$ENV{"SLURM_JOB_ID"} // undef
$ENV{"SLURM_JOB_ID"}
Truth table50%1/2
A
A= $ENV{"SLURM_JOB_ID"}
Aresult
11
00
27 GetOptions(
28 'u|user=s' => \$opt_user,
29 'n|name=s' => \$opt_name,
30 'r|refresh=i' => \$refresh_time,
31 'verbose' => \$opt_verbose_bool,
32 1 ▶ 'version' => sub { say "waitjobs v", $NBI::Slurm::VERSION; exit },
Subroutine __ANON__: called CC=1 SCAR=0.0
33 'debug' => \$opt_debug_bool,
34 0 ▶ 'help' => sub { usage() },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 1 );
36  
37 0 my $queue = NBI::Queue->new(
38 -username => $opt_user,
39 -name => $opt_name,
40 );
41 # If $self_job_id is anq integer, remove it from the queue
42 0 ▶if (defined $self_job_id and $self_job_id =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self_job_id and $self_job_id =~ /^\d+$/u) 0 0 0
Condition0%0/3
defined $self_job_id and $self_job_id =~ /^\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self_job_id and $self_job_id =~ /^\d+$/u
defined $self_job_id $self_job_id =~ /^\d+$/u
Truth table0%0/3
A and B
A= defined $self_job_idB= $self_job_id =~ /^\d+$/u
ABresult
0X0
100
111
43 0 print STDERR timelog("waitjobs"), "Ignoring current job id $self_job_id\n";
44 0 $queue->remove($self_job_id);
45 }
46  
47 0 my @starting_ids = @{$queue->ids()};
48 0 print STDERR timelog("waitjobs"), "There are ",
49 GREEN, BOLD, scalar @starting_ids, RESET " jobs for ",
50 GREEN, BOLD, $opt_user, RESET, " with name matching ",
51 GREEN, BOLD, $opt_name, RESET, "\n";
52  
53 0 ▶while (scalar @starting_ids > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @starting_ids > 0) 0 0 0
54 # Create the new queue with the same parameters as the initial queue
55 0 my $current_jobs = NBI::Queue->new(
56 -username => $opt_user,
57 -name => $opt_name,
58 );
59 0 my @current_ids = @{$current_jobs->ids()};
60  
61 # Remove from @starting_ids all the jobs that are NOT in @current_ids
62 0 my @new_starting_ids = ();
63 0 for my $starting_id (@starting_ids) {
64 0 ▶ if (grep {$_ eq $starting_id} @current_ids) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq $starting_id;} @current_ids) 0 0 0
65 0 push(@new_starting_ids, $starting_id);
66 }
67 }
68 0 @starting_ids = @new_starting_ids;
69 0 ▶ if ($opt_verbose_bool) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_verbose_bool) 0 0 0
70 0 say STDERR timelog("waitjobs"), "Waiting for ", scalar @starting_ids, " jobs to finish (refresh in $refresh_time seconds)";
71 }
72 0 sleep $refresh_time;
73 }
74  
75  
76 0 say STDERR timelog("waitjobs"), "No jobs left: quitting\n";
77  
78 0 ▶sub usage {
Subroutine usage: not called CC=1 SCAR=6.9
79 0 say STDERR<<END;
80  
81 Usage: waitjobs [options] [job_name]
82 ------------------------------------
83 Wait for selected jobs to exit the queue
84  
85 Options:
86 -u, --user default current user
87 -n, --name default '.+' (matches any name)
88 -r, --refresh check every 20 seconds
89
90 END
91 0 exit;
92 }
93  
94 __END__
« bin/printslurm ↑ Summary bin/printpath »