NAME

NBI::Job - A class for representing a job for NBI::Slurm

VERSION

version 0.1.1

SYNOPSIS

use NBI::Job;
my $job = NBI::Job->new(
  -name => "job-name",
  -command => "ls -l",
);

Multiple commands can be encoded as a list:

my $job = NBI::Job->new(
  -name => "job-name",
  -commands => ["ls -l", "echo done"]
);

SYNOPSIS

A job object supported from NBI::Slurm .

name

The actual sequence, the only mandatory field (string)

use NBI::Job;
my $job = new(
  -name => "job-name",
  -command => "ls -l",
);

# Multi commands
  my $job = new(
  -name => "job-name",
  -commands => ["ls -l", "echo done"]
);

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.

MAIN METHODS

new()

Create a new instance of NBI::Seq. The sequence is the only required field.

METHODS

new()

Create a new instance of NBI::Job. Note that the options must be made as NBI::Opts class.

my $job = NBI::Job->new(
   -name => "job-name",
   -command => "ls -l",
   -opts => $options
);

# Multi commands my $job = NBI::Job->new( -name => "job-name", -commands => ["ls -l", "echo done"] );

This method creates a new CNBI::Job object with the specified parameters. The following parameters are supported:

  • -name (string, optional): The name of the job. If not provided, a default name will be assigned.

  • -command (string, optional): The command to be executed by the job. Only one command can be specified using this parameter.

  • -commands (arrayref, optional): An array reference containing multiple commands to be executed by the job. If both -command and -commands are provided, the -command will be appended to the -commands array.

  • -opts (NBI::Opts object, optional): An instance of the NBI::Opts class representing the options for the job. If not provided, a default instance with the "nbi-short" queue will be used.

name

Accessor method for the job name.

$job->name = "new-name";
my $name = $job->name;

This method allows you to get or set the name of the job. If called with an argument, it sets the name of the job to the specified value. If called without an argument, it returns the current name of the job.

jobid

Accessor method for the job ID.

$job->jobid = 12345;
my $jobid = $job->jobid;

This method allows you to get or set the ID of the job. If called with an argument, it sets the ID of the job to the specified value. If called without an argument, it returns the current ID of the job. It's currently a public method but it's meant to be updated by the module itself.

outputfile

Accessor method for the output file path, where the output of the job will be written. Add %j in the name to use the JobID.

$job->outputfile = "/path/to/output.txt";
my $outputfile = $job->outputfile;

This method allows you to get or set the path of the output file generated by the job. If called with an argument, it sets the output file path to the specified value. If called without an argument, it returns the current output file path.

errorfile

Accessor method for the error file path.

$job->errorfile = "/path/to/error.txt";
my $errorfile = $job->errorfile;

This method allows you to get or set the path of the error file generated by the job. If called with an argument, it sets the error file path to the specified value. If called without an argument, it returns the current error file path.

append_command

Append a command to the job.

$job->append_command("echo done");

This method allows you to append a command to the list of commands executed by the job.

prepend_command

Prepend a command to the job.

$job->prepend_command("echo start");

This method allows you to prepend a command to the list of commands executed by the job.

commands

Get the list of commands for the job.

my $commands = $job->commands;

This method returns an array reference containing the commands to be executed by the job.

commands_count

Get the number of commands for the job.

my $count = $job->commands_count;

This method returns the number of commands defined for the job.

set_opts

Set the options for the job.

$job->set_opts($opts);

This method allows you to set the options for the job using an instance of the NBI::Opts class.

get_opts

Get the options for the job.

perl

my $opts = $job->get_opts;

This method returns the options for the job as an instance of the CNBI::Opts class.

opts

Accessor method for the options of the job.

my $opts = $job->opts;

This method returns the options for the job as an instance of the CNBI::Opts class.

script

Generate the sbatch script for the job.

my $script = $job->script;

This method generates the sbatch script for the job based on the current settings and returns it as a string.

run

Submit the job to SLURM.

my $jobid = $job->run;

This method submits the job to SLURM for execution. It generates the sbatch script, writes it to a file, and uses the "sbatch" command to submit the job. If the submission is successful, it returns the job ID assigned by SLURM. Otherwise, it throws an exception.

AUTHOR

Andrea Telatin <proch@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2023 by Andrea Telatin.

This is free software, licensed under:

The MIT (X11) License