NAME
NBI::Job - A class for representing a job for NBI::Slurm
VERSION
version 0.12.0
DESCRIPTION
The NBI::Job
module provides a class for representing a job to be submitted to SLURM for High-Performance Computing (HPC). It allows you to define the name of the job, the commands to be executed, and various options related to the job execution.
EXAMPLES
use
NBI::Job;
use
NBI::Opts;
# Create a simple job
my
$job
= NBI::Job->new(
-name
=>
"simple-job"
,
-command
=>
"echo 'Hello, World!'"
);
# Create a job with multiple commands
my
$multi_job
= NBI::Job->new(
-name
=>
"multi-command-job"
,
-commands
=> [
"echo 'Step 1'"
,
"sleep 5"
,
"echo 'Step 2'"
]
);
# Create a job with custom options: first define $opts and then $custom_job
my
$opts
= NBI::Opts->new(
-queue
=>
"long"
,
-memory
=>
"4GB"
,
-threads
=> 2,
-time
=>
"1h"
);
my
$custom_job
= NBI::Job->new(
-name
=>
"custom-job"
,
-command
=>
"run_analysis.pl"
,
-opts
=>
$opts
);
# Submit the job
my
$job_id
=
$custom_job
->run;
"Job submitted with ID: $job_id\n"
;
METHODS
new()
Create a new instance of NBI::Job
.
my
$job
= NBI::Job->new(
-name
=>
"job-name"
,
-command
=>
"ls -l"
,
-opts
=>
$options
);
# Or with multiple commands
my
$job
= NBI::Job->new(
-name
=>
"multi-step-job"
,
-commands
=> [
"step1.pl"
,
"step2.pl"
,
"step3.pl"
],
-opts
=>
$options
);
Parameters:
-name (string, optional): The name of the job. If not provided, a random name will be generated.
-command (string, optional): A single command to be executed by the job.
-commands (arrayref, optional): An array reference containing multiple commands to be executed by the job.
-opts (
NBI::Opts
object, optional): An instance of theNBI::Opts
class representing the options for the job. If not provided, default options will be used.
name
Accessor method for the job name.
$job
->name =
"new-job-name"
;
my
$name
=
$job
->name;
jobid
Accessor method for the job ID.
$job
->jobid = 12345;
# Usually set internally after job submission
my
$jobid
=
$job
->jobid;
outputfile
Accessor method for the output file path. Use %j
in the filename to include the job ID.
$job
->outputfile =
"job_output_%j.txt"
;
my
$outputfile
=
$job
->outputfile;
my
$interpolated_outputfile
=
$job
->outputfile(
'-interpolate'
);
errorfile
Accessor method for the error file path. Use %j
in the filename to include the job ID.
$job
->errorfile =
"job_error_%j.txt"
;
my
$errorfile
=
$job
->errorfile;
my
$interpolated_errorfile
=
$job
->errorfile(
'-interpolate'
);
script_path
Accessor method for the generated script path.
my
$script_path
=
$job
->script_path;
append_command
Append a command to the job.
$job
->append_command(
"echo 'Job finished'"
);
prepend_command
Prepend a command to the job.
$job
->prepend_command(
"echo 'Job starting'"
);
commands
Get the list of commands for the job.
my
$commands
=
$job
->commands;
foreach
my
$cmd
(
@$commands
) {
"Command: $cmd\n"
;
}
commands_count
Get the number of commands for the job.
my
$count
=
$job
->commands_count;
"This job has $count commands.\n"
;
set_opts
Set the options for the job.
my
$new_opts
= NBI::Opts->new(
-queue
=>
"short"
,
-memory
=>
"2GB"
);
$job
->set_opts(
$new_opts
);
get_opts
Get the options for the job.
my
$opts
=
$job
->get_opts;
"Job queue: "
.
$opts
->queue .
"\n"
;
opts
Alias for get_opts.
my
$opts
=
$job
->opts;
script
Generate the sbatch script for the job.
my
$script_content
=
$job
->script;
"Generated script:\n$script_content\n"
;
run
Submit the job to SLURM.
my
$submitted_job_id
=
$job
->run;
if
(
$submitted_job_id
) {
"Job submitted successfully with ID: $submitted_job_id\n"
;
}
else
{
"Job submission failed.\n"
;
}
view
Return a string representation of the job object.
my
$job_info
=
$job
->view;
$job_info
;
AUTHOR
Andrea Telatin <proch@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2023-2025 by Andrea Telatin.
This is free software, licensed under:
The MIT (X11) License