Class: Tengine::Job::Runtime::Execution

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps, Core::CollectionAccessible, Executable
Defined in:
lib/tengine/job/runtime/execution.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#signalObject

runを実行して、ackを返す際に一時的にsignalを記録しておく属性です。それ以外には使用しないでください。



29
30
31
# File 'lib/tengine/job/runtime/execution.rb', line 29

def signal
  @signal
end

Instance Method Details

#ack(signal) ⇒ Object



106
107
108
109
110
111
112
113
# File 'lib/tengine/job/runtime/execution.rb', line 106

def ack(signal)
  case phase_key
  when :ready then
    raise Tengine::Job::Runtime::Executable::PhaseError, "ack not available on #{phase_key.inspect}"
  when :starting then
    self.phase_key = :running
  end
end

#activate(signal) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/tengine/job/runtime/execution.rb', line 90

def activate(signal)
  case phase_key
  when :ready then
    self.phase_key = :starting
    if self.retry
      target_actuals.each do |target|
        target.transmit(signal)
      end
    else
      root_jobnet.transmit(signal)
    end
  else
    raise "Unsupported phase_key for activate: #{phase_key.inspect}"
  end
end

#actual_estimated_endObject

実開始日時から求める予定終了時刻



32
33
34
35
# File 'lib/tengine/job/runtime/execution.rb', line 32

def actual_estimated_end
  return nil unless started_at
  (started_at + (estimated_time || 0)).utc
end

#fail(signal) ⇒ Object



125
126
127
128
129
130
131
132
133
# File 'lib/tengine/job/runtime/execution.rb', line 125

def fail(signal)
  case phase_key
  when :initialized, :ready, :success then
    raise Tengine::Job::Runtime::Executable::PhaseError, "fail not available on #{phase_key.inspect}"
  when :starting, :running, :dying, :stuck then
    self.phase_key = :error
    signal.fire(self, :"error.execution.job.tengine")
  end
end

#in_scope?(vertex) ⇒ Boolean

Returns:



63
64
65
66
67
# File 'lib/tengine/job/runtime/execution.rb', line 63

def in_scope?(vertex)
  return false if vertex.nil?
  return true if target_actual_ids.nil? || target_actual_ids.empty?
  (vertex.id == scope_root.id) || vertex.ancestors.map(&:id).include?(scope_root.id)
end

#name_as_resourceObject



37
38
39
# File 'lib/tengine/job/runtime/execution.rb', line 37

def name_as_resource
  root_jobnet.name_as_resource.sub(/^job:/, 'execution:')
end

#scope_rootObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/tengine/job/runtime/execution.rb', line 52

def scope_root
  unless @scope_root
    actual = target_actuals.first
    @scope_root = spot ? actual : actual.parent || actual
    unless @scope_root
      raise "@scope_root must not be nil"
    end
  end
  @scope_root
end

#stop(signal) ⇒ Object

def fire_stop(signal) return if self.phase_key == :initialized signal.fire(self, :"stop.execution.job.tengine", { :execution_id => self.id, :root_jobnet_id => root_jobnet.id, :target_jobnet_id => root_jobnet.id, }) end



144
145
146
147
# File 'lib/tengine/job/runtime/execution.rb', line 144

def stop(signal)
  self.phase_key = :dying
  root_jobnet.fire_stop(signal)
end

#succeed(signal) ⇒ Object



115
116
117
118
119
120
121
122
123
# File 'lib/tengine/job/runtime/execution.rb', line 115

def succeed(signal)
  case phase_key
  when :initialized, :ready, :error then
    raise Tengine::Job::Runtime::Executable::PhaseError, "succeed not available on #{phase_key.inspect}"
  when :starting, :running, :dying, :stuck then
    self.phase_key = :success
    signal.fire(self, :"success.execution.job.tengine")
  end
end

#target_actualsObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/tengine/job/runtime/execution.rb', line 41

def target_actuals
  r = self.root_jobnet
  if target_actual_ids.nil? || target_actual_ids.empty?
    [r]
  else
    target_actual_ids.map do |target_actual_id|
      r.vertex(target_actual_id)
    end
  end
end

#transmit(signal) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tengine/job/runtime/execution.rb', line 69

def transmit(signal)
  case phase_key
  when :initialized then
    self.phase_key = :ready
    signal.call_later do
      if self.retry
        target_actuals.each do |target|
          signal.call_later{ signal.cache(target).reset(signal) }
        end
      end
      signal.call_later do
        Tengine.logger.info("=" * 50)
        activate(signal)
        self.save!
      end
    end
  else
    raise "Unsupported phase_key for transmit: #{phase_key.inspect}"
  end
end