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:


43
44
45
46
# File 'lib/ood_core/job/status.rb', line 43

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Boolean

Determine whether this method corresponds to a status check for a valid state. If so, then check whether this object is in that valid state.

Parameters:

  • method_name

    the method name called

  • arguments

    the arguments to the call

  • block

    an optional block for the call

Returns:

  • (Boolean)

    whether it is in this state

Raises:

  • (NoMethodError)

    if method name doesn't pass checks


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end

Instance Attribute Details

#stateSymbol (readonly)

Current status of submitted job

Returns:

  • (Symbol)

    status of job


39
40
41
# File 'lib/ood_core/job/status.rb', line 39

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

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

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

Instance Method Details

#==(other) ⇒ Boolean

The comparison operator

Parameters:

  • other (#to_sym)

    object to compare against

Returns:

  • (Boolean)

    whether objects are equivalent


63
64
65
# File 'lib/ood_core/job/status.rb', line 63

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

#completed?Boolean

Whether the status is completed

Returns:

  • (Boolean)

    whether completed


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  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


70
71
72
# File 'lib/ood_core/job/status.rb', line 70

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

#hashFixnum

Generate a hash value for this object

Returns:

  • (Fixnum)

    hash value of object


76
77
78
# File 'lib/ood_core/job/status.rb', line 76

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

#queued?Boolean

Whether the status is queued

Returns:

  • (Boolean)

    whether queued


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end

#queued_held?Boolean

Whether the status is queued_held

Returns:

  • (Boolean)

    whether queued_held


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Determines whether this method corresponds to a status check for a valid state

Parameters:

  • method_name

    the method name called

Returns:

  • (Boolean)

123
124
125
# File 'lib/ood_core/job/status.rb', line 123

def respond_to_missing?(method_name, include_private = false)
  /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym) || super
end

#running?Boolean

Whether the status is running

Returns:

  • (Boolean)

    whether running


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end

#suspended?Boolean

Whether the status is suspended

Returns:

  • (Boolean)

    whether suspended


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end

#to_sString

Convert object to string

Returns:

  • (String)

    object as string


56
57
58
# File 'lib/ood_core/job/status.rb', line 56

def to_s
  state.to_s
end

#to_symSymbol

Convert object to symbol

Returns:

  • (Symbol)

    object as symbol


50
51
52
# File 'lib/ood_core/job/status.rb', line 50

def to_sym
  state
end

#undetermined?Boolean

Whether the status is undetermined

Returns:

  • (Boolean)

    whether undetermined


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

def method_missing(method_name, *arguments, &block)
  if /^(?<other_state>.+)\?$/ =~ method_name && self.class.states.include?(other_state.to_sym)
    self == other_state
  else
    super
  end
end