Class: PBS::Batch
- Inherits:
-
Object
- Object
- PBS::Batch
- Defined in:
- lib/pbs/batch.rb
Overview
Object used for simplified communication with a batch server
Instance Attribute Summary collapse
-
#host ⇒ String
readonly
The host of the Torque batch server.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
The comparison operator.
-
#bin ⇒ Pathname
The path to the Torque client installation binaries.
-
#connect {|cid| ... } ⇒ Object
Creates a connection to batch server and calls block in context of this connection.
-
#delete_job(id) ⇒ void
Delete a specified job from batch server.
-
#eql?(other) ⇒ Boolean
Checks whether two batch server objects are completely identical to each other.
-
#get_job(id, **kwargs) ⇒ Hash
Get info for given batch server’s job.
-
#get_jobs(id: '', filters: []) ⇒ Hash
Get a list of hashes of the jobs on the batch server.
-
#get_node(id, **kwargs) ⇒ Hash
Get info for given batch server’s node.
-
#get_nodes(id: '', filters: []) ⇒ Hash
Get a list of hashes of the nodes on the batch server.
-
#get_queue(id, **kwargs) ⇒ Hash
Get info for given batch server’s queue.
-
#get_queues(id: '', filters: []) ⇒ Hash
Get a list of hashes of the queues on the batch server.
-
#get_status(filters: []) ⇒ Hash
Get a hash with status info for this batch server.
-
#hash ⇒ Fixnum
Generates a hash value for this object.
-
#hold_job(id, type: :u) ⇒ void
Put specified job on hold Possible hold types: :u => Available to the owner of the job, the batch operator and the batch administrator :o => Available to the batch operator and the batch administrator :s => Available to the batch administrator.
-
#initialize(host:, prefix: '', lib: nil, bin: nil, **_) ⇒ Batch
constructor
A new instance of Batch.
-
#lib ⇒ Pathname
The path to the Torque client installation libraries.
-
#release_job(id, type: :u) ⇒ void
Release a specified job that is on hold Possible hold types: :u => Available to the owner of the job, the batch operator and the batch administrator :o => Available to the batch operator and the batch administrator :s => Available to the batch administrator.
-
#submit_script(script, queue: nil, headers: {}, resources: {}, envvars: {}, qsub: true) ⇒ String
Submit a script to the batch server.
-
#submit_string(string, **kwargs) ⇒ String
Submit a script expanded into a string to the batch server.
-
#to_h ⇒ Hash
Convert object to hash.
Constructor Details
#initialize(host:, prefix: '', lib: nil, bin: nil, **_) ⇒ Batch
Returns a new instance of Batch.
46 47 48 49 50 51 |
# File 'lib/pbs/batch.rb', line 46 def initialize(host:, prefix: '', lib: nil, bin: nil, **_) @host = host.to_s @prefix = Pathname.new(prefix) @lib = Pathname.new(lib) if lib @bin = Pathname.new(bin) if bin end |
Instance Attribute Details
#host ⇒ String (readonly)
The host of the Torque batch server
10 11 12 |
# File 'lib/pbs/batch.rb', line 10 def host @host end |
Instance Method Details
#==(other) ⇒ Boolean
The comparison operator
62 63 64 |
# File 'lib/pbs/batch.rb', line 62 def ==(other) to_h == other.to_h end |
#bin ⇒ Pathname
The path to the Torque client installation binaries
33 34 35 36 37 38 39 40 |
# File 'lib/pbs/batch.rb', line 33 def bin @bin ||= if @prefix.join('bin').directory? @prefix.join('bin') else @prefix end end |
#connect {|cid| ... } ⇒ Object
Creates a connection to batch server and calls block in context of this connection
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/pbs/batch.rb', line 84 def connect(&block) Torque.lib = lib.join('libtorque.so') cid = Torque.pbs_connect(host) Torque.raise_error(cid.abs) if cid < 0 # raise error if negative connection id begin value = yield cid ensure Torque.pbs_disconnect(cid) # always close connection end Torque.check_for_error # check for errors at end value end |
#delete_job(id) ⇒ void
This method returns an undefined value.
Delete a specified job from batch server
284 285 286 287 288 |
# File 'lib/pbs/batch.rb', line 284 def delete_job(id) connect do |cid| Torque.pbs_deljob cid, id.to_s, nil end end |
#eql?(other) ⇒ Boolean
Checks whether two batch server objects are completely identical to each other
70 71 72 |
# File 'lib/pbs/batch.rb', line 70 def eql?(other) self.class == other.class && self == other end |
#get_job(id, **kwargs) ⇒ Hash
Get info for given batch server’s job
243 244 245 |
# File 'lib/pbs/batch.rb', line 243 def get_job(id, **kwargs) get_jobs(id: id, **kwargs) end |
#get_jobs(id: '', filters: []) ⇒ Hash
Get a list of hashes of the jobs on the batch server
222 223 224 225 226 227 228 |
# File 'lib/pbs/batch.rb', line 222 def get_jobs(id: '', filters: []) connect do |cid| filters = PBS::Torque::Attrl.from_list(filters) batch_status = Torque.pbs_statjob cid, id.to_s, filters, nil batch_status.to_h.tap { Torque.pbs_statfree batch_status } end end |
#get_node(id, **kwargs) ⇒ Hash
Get info for given batch server’s node
198 199 200 |
# File 'lib/pbs/batch.rb', line 198 def get_node(id, **kwargs) get_nodes(id: id, **kwargs) end |
#get_nodes(id: '', filters: []) ⇒ Hash
Get a list of hashes of the nodes on the batch server
178 179 180 181 182 183 184 |
# File 'lib/pbs/batch.rb', line 178 def get_nodes(id: '', filters: []) connect do |cid| filters = PBS::Torque::Attrl.from_list(filters) batch_status = Torque.pbs_statnode cid, id.to_s, filters, nil batch_status.to_h.tap { Torque.pbs_statfree batch_status } end end |
#get_queue(id, **kwargs) ⇒ Hash
Get info for given batch server’s queue
155 156 157 |
# File 'lib/pbs/batch.rb', line 155 def get_queue(id, **kwargs) get_queues(id: id, **kwargs) end |
#get_queues(id: '', filters: []) ⇒ Hash
Get a list of hashes of the queues on the batch server
135 136 137 138 139 140 141 |
# File 'lib/pbs/batch.rb', line 135 def get_queues(id: '', filters: []) connect do |cid| filters = PBS::Torque::Attrl.from_list(filters) batch_status = Torque.pbs_statque cid, id.to_s, filters, nil batch_status.to_h.tap { Torque.pbs_statfree batch_status } end end |
#get_status(filters: []) ⇒ Hash
Get a hash with status info for this batch server
109 110 111 112 113 114 115 |
# File 'lib/pbs/batch.rb', line 109 def get_status(filters: []) connect do |cid| filters = PBS::Torque::Attrl.from_list filters batch_status = Torque.pbs_statserver cid, filters, nil batch_status.to_h.tap { Torque.pbs_statfree batch_status } end end |
#hash ⇒ Fixnum
Generates a hash value for this object
76 77 78 |
# File 'lib/pbs/batch.rb', line 76 def hash [self.class, to_h].hash end |
#hold_job(id, type: :u) ⇒ void
This method returns an undefined value.
Put specified job on hold Possible hold types:
:u => Available to the owner of the job, the batch operator and the batch administrator
:o => Available to the batch operator and the batch administrator
:s => Available to the batch administrator
257 258 259 260 261 |
# File 'lib/pbs/batch.rb', line 257 def hold_job(id, type: :u) connect do |cid| Torque.pbs_holdjob cid, id.to_s, type.to_s, nil end end |
#lib ⇒ Pathname
The path to the Torque client installation libraries
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pbs/batch.rb', line 16 def lib @lib ||= if @prefix.join('lib').directory? @prefix.join('lib') elsif @prefix.join('lib32').directory? @prefix.join('lib32') elsif @prefix.join('lib64').directory? @prefix.join('lib64') else @prefix end end |
#release_job(id, type: :u) ⇒ void
This method returns an undefined value.
Release a specified job that is on hold Possible hold types:
:u => Available to the owner of the job, the batch operator and the batch administrator
:o => Available to the batch operator and the batch administrator
:s => Available to the batch administrator
273 274 275 276 277 |
# File 'lib/pbs/batch.rb', line 273 def release_job(id, type: :u) connect do |cid| Torque.pbs_rlsjob cid, id.to_s, type.to_s, nil end end |
#submit_script(script, queue: nil, headers: {}, resources: {}, envvars: {}, qsub: true) ⇒ String
Submit a script to the batch server
313 314 315 |
# File 'lib/pbs/batch.rb', line 313 def submit_script(script, queue: nil, headers: {}, resources: {}, envvars: {}, qsub: true) send(qsub ? :qsub_submit : :pbs_submit, script, queue, headers, resources, envvars) end |
#submit_string(string, **kwargs) ⇒ String
Submit a script expanded into a string to the batch server
321 322 323 324 325 326 327 |
# File 'lib/pbs/batch.rb', line 321 def submit_string(string, **kwargs) Tempfile.open('qsub.') do |f| f.write string.to_s f.close submit_script(f.path, **kwargs) end end |
#to_h ⇒ Hash
Convert object to hash
55 56 57 |
# File 'lib/pbs/batch.rb', line 55 def to_h {host: host, lib: lib, bin: bin} end |