Class: Backburner::Job

Inherits:
BackburnerObject show all
Defined in:
lib/backburner/job.rb

Constant Summary collapse

JOB_STATES =
[:complete, :not_started, :waiting, :suspended, :running]

Instance Attribute Summary

Attributes inherited from BackburnerObject

#handler

Instance Method Summary collapse

Methods inherited from BackburnerObject

#initialize, #method_missing, #reload

Constructor Details

This class inherits a constructor from Backburner::BackburnerObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Backburner::BackburnerObject

Instance Method Details

#load_raw_dataObject



7
8
9
# File 'lib/backburner/job.rb', line 7

def load_raw_data
  @connection.job.get(handler)
end

#nameObject



31
32
33
# File 'lib/backburner/job.rb', line 31

def name
  @raw_data.job.job_info.name
end

#server_timeObject



19
20
21
22
23
# File 'lib/backburner/job.rb', line 19

def server_time
  servers.inject(0.0) do |sum, server|
    sum += server.time
  end
end

#serversObject



11
12
13
14
15
16
17
# File 'lib/backburner/job.rb', line 11

def servers
  return [] if !@raw_data || !@raw_data.job.servers || !@raw_data.job.servers.server
  servers = @raw_data.job.servers.server.is_a?(Array) ? @raw_data.job.servers.server : [@raw_data.job.servers.server]
  servers.map do |server|
    JobServer.new server, @connection
  end
end

#stateObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/backburner/job.rb', line 35

def state
  @connection.jobstate.get(@raw_data.job.job_info.handle)
  case @connection.last_size
    when 0 then :complete
    when 1 then :not_started
    when 2 then :running
    when 3 then :suspended
    when 4 then :waiting
    else :undefined
  end
end

#walltimeObject



25
26
27
28
29
# File 'lib/backburner/job.rb', line 25

def walltime
  @raw_data.job.job_info.ended - @raw_data.job.job_info.started
rescue
  0.0
end