Class: OSC::Machete::Status

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/osc/machete/status.rb

Overview

Value object representing job status independent of underlying resource manager.

All of the possible Torque statuses are not represented here. Its the responsibility of the Torque adapter (TorqueHelper) to create the appropriate Status object to represent the Torque status.

The possible values are: Undetermined, Not Submitted, Passed, Failed, Held, Queued, Running, Suspended

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char) ⇒ Status

Returns a new instance of Status.



130
131
132
133
134
135
136
137
# File 'lib/osc/machete/status.rb', line 130

def initialize(char)
  # char could be a status object or a string
  @char = (char.respond_to?(:char) ? char.char : char).to_s.upcase
  @char = nil if @char.empty?

  # if invalid status value char, default to undetermined
  @char = self.class.undetermined.char unless VALUES_HASH.has_key?(@char)
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



12
13
14
# File 'lib/osc/machete/status.rb', line 12

def char
  @char
end

Class Method Details

.active_valuesArray<Status>

Get an array of all the possible active Status values

Returns:

  • (Array<Status>)
    • all possible active Status values



46
47
48
# File 'lib/osc/machete/status.rb', line 46

def self.active_values
  values.select(&:active?)
end

.completed_valuesArray<Status>

Get an array of all the possible completed Status values

Returns:

  • (Array<Status>)
    • all possible completed Status values



53
54
55
# File 'lib/osc/machete/status.rb', line 53

def self.completed_values
  values.select(&:completed?)
end

.failedStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.heldStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.not_submittedStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.passedStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.queuedStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.runningStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.suspendedStatus

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.undeterminedStatus

A ‘null’ special case for Status

Returns:



94
95
96
97
98
# File 'lib/osc/machete/status.rb', line 94

VALUES_HASH.each do |char, name|
  define_method(name) do
    OSC::Machete::Status.new(char)
  end
end

.valuesArray<Status>

Get an array of all the possible Status values

Returns:

  • (Array<Status>)
    • all possible Status values



39
40
41
# File 'lib/osc/machete/status.rb', line 39

def self.values
  VALUES.map{ |v| OSC::Machete::Status.new(v.first) }
end

Instance Method Details

#+(other) ⇒ Object

Return the a StatusValue object based on the highest precedence of the two objects.

Return [OSC::Machete::Status] The max status by precedence

Examples:

One job is running and a dependent job is queued.

OSC::Machete::Status.running + OSC::Machete::Status.queued #=> Running


171
172
173
# File 'lib/osc/machete/status.rb', line 171

def +(other)
  [self, other].max
end

#<=>(other) ⇒ Integer

The comparison operator for sorting values.

Returns:

  • (Integer)

    Comparison value based on precedence



178
179
180
# File 'lib/osc/machete/status.rb', line 178

def <=>(other)
  precedence <=> other.precedence
end

#==(other) ⇒ Boolean

Boolean evaluation of Status object equality.

Returns:

  • (Boolean)

    True if the values are the same



193
194
195
# File 'lib/osc/machete/status.rb', line 193

def ==(other)
  self.eql?(other)
end

#active?Boolean

Returns true if in active state (running, queued, held, suspended).

Returns:

  • (Boolean)

    true if in active state (running, queued, held, suspended)



145
146
147
# File 'lib/osc/machete/status.rb', line 145

def active?
  running? || queued? || held? || suspended?
end

#completed?Boolean

Returns true if in completed state (passed or failed).

Returns:

  • (Boolean)

    true if in completed state (passed or failed)



150
151
152
# File 'lib/osc/machete/status.rb', line 150

def completed?
  passed? || failed?
end

#eql?(other) ⇒ Boolean

Boolean evaluation of Status object equality.

Returns:

  • (Boolean)

    True if the values are the same



185
186
187
188
# File 'lib/osc/machete/status.rb', line 185

def eql?(other)
  # compare Status to Status OR "C" to Status
  (other.respond_to?(:char) ? other.char : other) == char
end

#failed?Boolean

Returns true if failed.

Returns:

  • (Boolean)

    true if failed



# File 'lib/osc/machete/status.rb', line 107


#hashFixnum

Return a hash based on the char value of the object.

Returns:

  • (Fixnum)

    A hash value of the status char



200
201
202
# File 'lib/osc/machete/status.rb', line 200

def hash
  @char.hash
end

#held?Boolean

Returns true if held.

Returns:

  • (Boolean)

    true if held



# File 'lib/osc/machete/status.rb', line 113


#not_submitted?Boolean

Returns true if not_submitted.

Returns:

  • (Boolean)

    true if not_submitted



# File 'lib/osc/machete/status.rb', line 104


#passed?Boolean

Returns true if passed.

Returns:

  • (Boolean)

    true if passed



# File 'lib/osc/machete/status.rb', line 110


#precedenceInteger

Return the ordinal position of the status in the precidence list

Returns:

  • (Integer)

    The order of precedence for the object



207
208
209
210
# File 'lib/osc/machete/status.rb', line 207

def precedence
  # Hashes enumerate their values in the order that the corresponding keys were inserted
  PRECEDENCE.index(@char)
end

#queued?Boolean

Returns true if queued.

Returns:

  • (Boolean)

    true if queued



# File 'lib/osc/machete/status.rb', line 116


#running?Boolean

Returns true if running.

Returns:

  • (Boolean)

    true if running



# File 'lib/osc/machete/status.rb', line 119


#submitted?Boolean

Returns true if submitted.

Returns:

  • (Boolean)

    true if submitted



140
141
142
# File 'lib/osc/machete/status.rb', line 140

def 
  ! ( || undetermined?)
end

#suspended?Boolean

Returns true if suspended.

Returns:

  • (Boolean)

    true if suspended



124
125
126
127
128
# File 'lib/osc/machete/status.rb', line 124

VALUES_HASH.each do |char, name|
  define_method("#{name}?") do
    self == OSC::Machete::Status.new(char)
  end
end

#to_sString

Return a readable string of the status

Examples:

Running

OSC::Machete::Status.running.to_s #=> "Running"

Returns:

  • (String)

    The status value as a formatted string



160
161
162
163
# File 'lib/osc/machete/status.rb', line 160

def to_s
  # FIXME: ActiveSupport  replace with .humanize and simpler datastructure
   VALUES_HASH[@char].split("_").map(&:capitalize).join(" ")
end

#undetermined?Boolean

Returns true if undetermined.

Returns:

  • (Boolean)

    true if undetermined



# File 'lib/osc/machete/status.rb', line 101