lib/NBI/Pipeline.pm

filter: Statementstmt 95.9% 47 / 49 Branchbran 62.5% 10 / 16 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 83.5% 71 / 85 CC 14 SCAR 15.8
CC
14
Cov
84%
run
8.4
new
5.1
print_summary
3.0
CRAP 4.8
« bin/whojobs ↑ Summary blib/lib/NBI/Launcher/RemovePrimers.pm »
1 package NBI::Pipeline;
2 #ABSTRACT: Ordered list of NBI::Job objects with dependency wiring
3 #
4 # NBI::Pipeline - Minimal multi-job orchestration for nbilaunch.
5 #
6 # DESCRIPTION:
7 # Holds an ordered list of NBI::Job objects. When run() is called, jobs are
8 # submitted in order. If a job has _nbi_depends_on set to a previous job
9 # object, the afterok dependency is injected into its NBI::Opts before
10 # submission.
11 #
12 # This is intentionally minimal in v1. It does not resolve filenames between
13 # jobs - complex launchers handle that via NBI::Manifest->load().
14 #
15 # USAGE IN A LAUNCHER:
16 # sub build {
17 # my ($self, %args) = @_;
18 # my ($job1, $m1) = $self->_build_step1(%args);
19 # my ($job2, $m2) = $self->_build_step2(%args);
20 # $job2->{_nbi_depends_on} = $job1;
21 # return (NBI::Pipeline->new(jobs => [$job1, $job2]), $m1);
22 # }
23 #
24 # nbilaunch checks ref($result): NBI::Job → single submit, NBI::Pipeline → run().
25 #
26  
27 1 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 $NBI::Pipeline::VERSION = $NBI::Slurm::VERSION;
33  
34 5 ▶sub new {
Subroutine new: called CC=5 SCAR=16.3
Pod documented
35 5 my ($class, %args) = @_;
36  
37 5 ▶ my $jobs = $args{jobs} // [];
Condition50%1/2
$args{"jobs"} // []
l!l
50
MC/DC0%0/1
$args{"jobs"} // []
$args{"jobs"}
Truth table50%1/2
A
A= $args{"jobs"}
Aresult
11
00
38 5 ▶ ref $jobs eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $jobs eq "ARRAY" or confess("ERROR NBI::Pipeline: 'jobs' must be an arrayref\n") 5 0 5
39 or confess "ERROR NBI::Pipeline: 'jobs' must be an arrayref\n";
40  
41 5 for my $j (@$jobs) {
42 9 ▶ $j->isa('NBI::Job')
Branch: 1 branch
BranchTrueFalseTotal
$j->isa("NBI::Job") or confess("ERROR NBI::Pipeline: each job must be an NBI::Job instance\n") 8 1 9
43 or confess "ERROR NBI::Pipeline: each job must be an NBI::Job instance\n";
44 }
45  
46 4 return bless { jobs => [@$jobs] }, $class;
47 }
48  
49 # ── add_job($job) ─────────────────────────────────────────────────────────────
50 1 ▶sub add_job {
Subroutine add_job: called CC=2 SCAR=7.0
Pod documented
51 1 my ($self, $job) = @_;
52 1 ▶ $job->isa('NBI::Job')
Branch: 1 branch
BranchTrueFalseTotal
$job->isa("NBI::Job") or confess("ERROR NBI::Pipeline: job must be an NBI::Job instance\n") 1 0 1
53 or confess "ERROR NBI::Pipeline: job must be an NBI::Job instance\n";
54 1 push @{ $self->{jobs} }, $job;
55 1 return $self;
56 }
57  
58 # ── run() ─────────────────────────────────────────────────────────────────────
59 # Submit all jobs in order. Wires afterok dependencies automatically.
60 # Returns a list of Slurm job IDs (integers).
61 2 ▶sub run {
Subroutine run: called CC=7 SCAR=21.3
Pod documented
62 2 my ($self) = @_;
63  
64 2 my @job_ids;
65 my %submitted; # NBI::Job object → job_id (for dependency lookup)
66  
67 2 for my $job (@{ $self->{jobs} }) {
68 # Inject afterok dependency if this job depends on a previous one
69 4 ▶ if (my $dep_job = $job->{_nbi_depends_on}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dep_job = $job->{"_nbi_depends_on"}) 1 3 4
70 1 ▶ my $dep_id = $submitted{$dep_job}
Branch: 1 branch
BranchTrueFalseTotal
my $dep_id = $submitted{$dep_job} or confess("ERROR NBI::Pipeline: dependency job was not yet submitted\n") 1 0 1
71 or confess "ERROR NBI::Pipeline: dependency job was not yet submitted\n";
72 1 $job->opts->add_option("--dependency=afterok:$dep_id");
73 }
74  
75 # Ensure the provenance directory exists before NBI::Job->run() writes there
76 4 my $tmpdir = $job->opts->tmpdir;
77 4 ▶ if ($tmpdir && !-d $tmpdir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tmpdir and not -d $tmpdir) 0 4 4
Condition33%1/3
$tmpdir and not -d $tmpdir
!ll&&!rl&&r
040
MC/DC0%0/2
$tmpdir and not -d $tmpdir
$tmpdir not -d $tmpdir
Truth table33%1/3
A and not(B)
A= $tmpdirB= not -d $tmpdir
ABresult
0X0
100
111
78 0 require File::Path;
79 0 ▶ File::Path::make_path($tmpdir)
Branch: 1 branch
BranchTrueFalseTotal
File::Path::make_path($tmpdir) or confess("ERROR NBI::Pipeline: cannot create tmpdir '${tmpdir}': $!\n") 0 0 0
80 or confess "ERROR NBI::Pipeline: cannot create tmpdir '$tmpdir': $!\n";
81 }
82  
83 4 my $job_id = $job->run();
84 4 $submitted{$job} = $job_id;
85 4 push @job_ids, $job_id;
86 }
87  
88 2 return @job_ids;
89 }
90  
91 # ── print_summary() ───────────────────────────────────────────────────────────
92 # Human-readable dependency graph.
93 1 ▶sub print_summary {
Subroutine print_summary: called CC=3 SCAR=11.0
Pod documented
94 1 my ($self) = @_;
95 1 my @lines = ("Pipeline: " . scalar(@{ $self->{jobs} }) . " job(s)");
96 1 for my $job (@{ $self->{jobs} }) {
97 2 my $line = " [" . $job->name . "]";
98 2 ▶ if (my $dep = $job->{_nbi_depends_on}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $dep = $job->{"_nbi_depends_on"}) 1 1 2
99 1 $line .= " afterok:[" . $dep->name . "]";
100 }
101 2 push @lines, $line;
102 }
103 1 print join("\n", @lines) . "\n";
104 }
105  
106 1 1;
107  
108 __END__
« bin/whojobs ↑ Summary blib/lib/NBI/Launcher/RemovePrimers.pm »