Class: OodCore::Job::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/ood_core/job/status.rb

Overview

An object that describes the current state of a submitted job.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state:, **_) ⇒ Status

Returns a new instance of Status.

Parameters:

  • state (#to_sym)

    status of job

Raises:



45
46
47
48
# File 'lib/ood_core/job/status.rb', line 45

def initialize(state:, **_)
  @state = state.to_sym
  raise UnknownStateAttribute, "arguments specify unknown '#{@state}' state" unless self.class.states.include?(@state)
end

Instance Attribute Details

#stateSymbol (readonly)

Current status of submitted job

Returns:

  • (Symbol)

    status of job



41
42
43
# File 'lib/ood_core/job/status.rb', line 41

def state
  @state
end

Class Method Details

.statesObject

Possible states a submitted job can be in:

# Job status cannot be determined
:undetermined

# Job is queued for being scheduled and executed
:queued

# Job has been placed on hold by the system, the administrator, or
# submitting user
:queued_held

# Job is running on an execution host
:running

# Job has been suspended by the user, the system, or the administrator
:suspended

# Job is completed and not running on an execution host
:completed

@note that this list's order is meaningful and should not be sorted lexigraphically


27
28
29
30
31
32
33
34
35
36
# File 'lib/ood_core/job/status.rb', line 27

def states
  %i(
    undetermined
    completed
    queued_held
    queued
    running
    suspended
  )
end

Instance Method Details

#<=>(other) ⇒ Integer

The comparison operator for sorting values.

Returns:

  • (Integer)

    Comparison value based on precedence



126
127
128
# File 'lib/ood_core/job/status.rb', line 126

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

#==(other) ⇒ Boolean

The comparison operator

Parameters:

  • other (#to_sym)

    object to compare against

Returns:

  • (Boolean)

    whether objects are equivalent



65
66
67
# File 'lib/ood_core/job/status.rb', line 65

def ==(other)
  to_sym == other.to_sym
end

#completed?Boolean

Whether the status is completed

Returns:

  • (Boolean)

    whether completed



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end

#eql?(other) ⇒ Boolean

Whether objects are identical to each other

Parameters:

  • other (#to_sym)

    object to compare against

Returns:

  • (Boolean)

    whether objects are identical



72
73
74
# File 'lib/ood_core/job/status.rb', line 72

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

#hashInteger

Generate a hash value for this object

Returns:

  • (Integer)

    hash value of object



78
79
80
# File 'lib/ood_core/job/status.rb', line 78

def hash
  [self.class, to_sym].hash
end

#precedenceObject



119
120
121
# File 'lib/ood_core/job/status.rb', line 119

def precedence
  self.class.states.index(@state)
end

#queued?Boolean

Whether the status is queued

Returns:

  • (Boolean)

    whether queued



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end

#queued_held?Boolean

Whether the status is queued_held

Returns:

  • (Boolean)

    whether queued_held



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end

#running?Boolean

Whether the status is running

Returns:

  • (Boolean)

    whether running



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end

#suspended?Boolean

Whether the status is suspended

Returns:

  • (Boolean)

    whether suspended



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end

#to_sString

Convert object to string

Returns:

  • (String)

    object as string



58
59
60
# File 'lib/ood_core/job/status.rb', line 58

def to_s
  state.to_s
end

#to_symSymbol

Convert object to symbol

Returns:

  • (Symbol)

    object as symbol



52
53
54
# File 'lib/ood_core/job/status.rb', line 52

def to_sym
  state
end

#undetermined?Boolean

Whether the status is undetermined

Returns:

  • (Boolean)

    whether undetermined



113
114
115
116
117
# File 'lib/ood_core/job/status.rb', line 113

states.each do |state|
  define_method("#{state}?") do
    self == state
  end
end