Class: OodCore::Job::Adapters::Slurm::Batch Private
- Inherits:
-
Object
- Object
- OodCore::Job::Adapters::Slurm::Batch
- Defined in:
- lib/ood_core/job/adapters/slurm.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Object used for simplified communication with a Slurm batch server
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#bin ⇒ Pathname
readonly
private
The path to the Slurm client installation binaries.
-
#cluster ⇒ String?
readonly
private
The cluster of the Slurm batch server.
-
#conf ⇒ Pathname?
readonly
private
The path to the Slurm configuration file.
Instance Method Summary collapse
-
#delete_job(id) ⇒ void
private
Delete a specified job from batch server.
-
#get_jobs(id: "", filters: []) ⇒ Array<Hash>
private
Get a list of hashes detailing each of the jobs on the batch server.
-
#hold_job(id) ⇒ void
private
Put a specified job on hold.
-
#initialize(cluster: nil, bin: nil, conf: nil) ⇒ Batch
constructor
private
A new instance of Batch.
-
#release_job(id) ⇒ void
private
Release a specified job that is on hold.
-
#submit_string(str, args: [], env: {}) ⇒ String
private
Submit a script expanded as a string to the batch server.
Constructor Details
#initialize(cluster: nil, bin: nil, conf: nil) ⇒ Batch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Batch.
58 59 60 61 62 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 58 def initialize(cluster: nil, bin: nil, conf: nil) @cluster = cluster && cluster.to_s @conf = conf && Pathname.new(conf.to_s) @bin = Pathname.new(bin.to_s) end |
Instance Attribute Details
#bin ⇒ Pathname (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the Slurm client installation binaries
49 50 51 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 49 def bin @bin end |
#cluster ⇒ String? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The cluster of the Slurm batch server
37 38 39 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 37 def cluster @cluster end |
#conf ⇒ Pathname? (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the Slurm configuration file
43 44 45 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 43 def conf @conf end |
Instance Method Details
#delete_job(id) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Delete a specified job from batch server
124 125 126 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 124 def delete_job(id) call("scancel", id.to_s) end |
#get_jobs(id: "", filters: []) ⇒ Array<Hash>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a list of hashes detailing each of the jobs on the batch server
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 85 def get_jobs(id: "", filters: []) delim = "\x1F" # don't use "|" because FEATURES uses this = filters.empty? ? fields : fields.slice(*filters) args = ["--all", "--states=all", "--noconvert"] args += ["-o", "#{.values.join(delim)}"] args += ["-j", id.to_s] unless id.to_s.empty? lines = call("squeue", *args).split("\n").map(&:strip) lines.drop(cluster ? 2 : 1).map do |line| Hash[.keys.zip(line.split(delim))] end end |
#hold_job(id) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Put a specified job on hold
104 105 106 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 104 def hold_job(id) call("scontrol", "hold", id.to_s) end |
#release_job(id) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Release a specified job that is on hold
114 115 116 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 114 def release_job(id) call("scontrol", "release", id.to_s) end |
#submit_string(str, args: [], env: {}) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Submit a script expanded as a string to the batch server
134 135 136 137 138 |
# File 'lib/ood_core/job/adapters/slurm.rb', line 134 def submit_string(str, args: [], env: {}) args = args.map(&:to_s) + ["--parsable"] env = {"SBATCH_EXPORT" => "NONE"}.merge env.each_with_object({}) { |(k, v), h| h[k.to_s] = v.to_s } call("sbatch", *args, env: env, stdin: str.to_s).strip.split(";").first end |