Class: TORQUE::Qstat
- Inherits:
-
Object
- Object
- TORQUE::Qstat
- Defined in:
- lib/torque_rm/qstat.rb
Defined Under Namespace
Classes: EnanchedOpenStruct, Job
Class Method Summary collapse
-
.fields ⇒ Object
initialize.
Instance Method Summary collapse
-
#display(hash = {}) ⇒ Object
query.
- #fields ⇒ Object
-
#initialize ⇒ Qstat
constructor
A new instance of Qstat.
- #mock(results) ⇒ Object
-
#query(hash = {}) ⇒ Object
hash can contain keys: type = :raw just print a string job_id = job.id it will print info only about the specified job job_ids = [“1.server”, “2.server”, “3.server”] get an array for requested jobs returns results which is an Array of Job.
Constructor Details
#initialize ⇒ Qstat
Returns a new instance of Qstat.
254 255 256 257 258 |
# File 'lib/torque_rm/qstat.rb', line 254 def initialize # @parser = Parser.new #DEPRECATED # @transformer = Trans.new #DEPRECATED @last_query = nil #cache last query, it can be useful to generate some kind of statistics ? end |
Class Method Details
.fields ⇒ Object
initialize
260 261 262 |
# File 'lib/torque_rm/qstat.rb', line 260 def self.fields FIELDS end |
Instance Method Details
#display(hash = {}) ⇒ Object
query
320 321 322 323 |
# File 'lib/torque_rm/qstat.rb', line 320 def display(hash={}) query(hash) print_jobs_table(@last_query) end |
#fields ⇒ Object
264 265 266 |
# File 'lib/torque_rm/qstat.rb', line 264 def fields FIELDS end |
#mock(results) ⇒ Object
325 326 327 |
# File 'lib/torque_rm/qstat.rb', line 325 def mock(results) from_parselet_to_jobs(results) end |
#query(hash = {}) ⇒ Object
hash can contain keys: type = :raw just print a string job_id = job.id it will print info only about the specified job job_ids = [“1.server”, “2.server”, “3.server”] get an array for requested jobs returns results which is an Array of Job
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# File 'lib/torque_rm/qstat.rb', line 273 def query(hash={}) # result = TORQUE.server.qstat('-f') if hash[:type] == :raw TORQUE.server.qstat('-f').to_s #returns elsif hash[:type] == :xml TORQUE.server.qstat('-f','-x') #returns else # begin data_xml = Hash.from_xml(TORQUE.server.qstat('-f','-x').to_s) @last_query = if data_xml.nil? [] #returns else data_array = data_xml["Data"]["Job"].is_a?(Hash) ? [data_xml["Data"]["Job"]] : data_xml["Data"]["Job"] jobs = data_array.map do |job_xml| Job.new job_xml end # do if hash.key? :job_id # if hash[:job_id]..is_a? String jobs.select {|job| (hash[:job_id].to_s == job.job_id || hash[:job_id].to_s == job.job_id.split(".").first)} # else # warn "You gave me #{hash[:job_id].class}, only String is supported." # end elsif hash.key? :job_ids if hash[:job_ids].is_a? Array jobs.select {|job| (hash[:job_ids].include?(job.job_id) || hash[:job_ids].include?(job.job_id.split(".").first))} elsif hash[:job_ids].is_a? String warn "To be implemented for String object." else warm "To be implemented for #{hash[:job_ids].class}" end else jobs end end # else # puts result.to_s.inspect # puts result.to_s.gsub(/\n\t/,'').inspect # results = @transformer.apply(@parser.parse(result.to_s.gsub(/\n\t/,''))) # rescue Parslet::ParseFailed => failure # puts failure.cause.ascii_tree # end # results = [] if results.is_a?(String) && results.empty? # @last_query = from_parselet_to_jobs(results) end end |