Class: Tengine::Job::Execution
- Inherits:
-
Object
- Object
- Tengine::Job::Execution
- Includes:
- Mongoid::Document, Mongoid::Timestamps, Core::CollectionAccessible, Executable
- Defined in:
- lib/tengine/job/execution.rb
Instance Attribute Summary collapse
-
#signal ⇒ Object
runを実行して、ackを返す際に一時的にsignalを記録しておく属性です。それ以外には使用しないでください。.
Instance Method Summary collapse
- #ack(signal) ⇒ Object
- #activate(signal) ⇒ Object
-
#actual_estimated_end ⇒ Object
実開始日時から求める予定終了時刻.
- #fail(signal) ⇒ Object
- #in_scope?(vertex) ⇒ Boolean
- #name_as_resource ⇒ Object
- #scope_root ⇒ Object
-
#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.
- #succeed(signal) ⇒ Object
- #target_actuals ⇒ Object
- #transmit(signal) ⇒ Object
Instance Attribute Details
#signal ⇒ Object
runを実行して、ackを返す際に一時的にsignalを記録しておく属性です。それ以外には使用しないでください。
27 28 29 |
# File 'lib/tengine/job/execution.rb', line 27 def signal @signal end |
Instance Method Details
#ack(signal) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/tengine/job/execution.rb', line 98 def ack(signal) case phase_key when :ready then raise Tengine::Job::Executable::PhaseError, "ack not available on #{phase_key.inspect}" when :starting then self.phase_key = :running end end |
#activate(signal) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tengine/job/execution.rb', line 82 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_end ⇒ Object
実開始日時から求める予定終了時刻
30 31 32 33 |
# File 'lib/tengine/job/execution.rb', line 30 def actual_estimated_end return nil unless started_at (started_at + (estimated_time || 0)).utc end |
#fail(signal) ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'lib/tengine/job/execution.rb', line 117 def fail(signal) case phase_key when :initialized, :ready, :success then raise Tengine::Job::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
61 62 63 64 65 |
# File 'lib/tengine/job/execution.rb', line 61 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_resource ⇒ Object
35 36 37 |
# File 'lib/tengine/job/execution.rb', line 35 def name_as_resource root_jobnet.name_as_resource.sub(/^job:/, 'execution:') end |
#scope_root ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/tengine/job/execution.rb', line 50 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
136 137 138 139 |
# File 'lib/tengine/job/execution.rb', line 136 def stop(signal) self.phase_key = :dying root_jobnet.fire_stop(signal) end |
#succeed(signal) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/tengine/job/execution.rb', line 107 def succeed(signal) case phase_key when :initialized, :ready, :error then raise Tengine::Job::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_actuals ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tengine/job/execution.rb', line 39 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tengine/job/execution.rb', line 67 def transmit(signal) case phase_key when :initialized then if self.retry target_actuals.each do |target| target.reset(signal) end end self.phase_key = :ready activate(signal) else raise "Unsupported phase_key for transmit: #{phase_key.inspect}" end end |