Class: Tengine::Job::Edge
- Inherits:
-
Object
- Object
- Tengine::Job::Edge
show all
- Includes:
- Mongoid::Document, Mongoid::Timestamps, Core::SelectableAttr, Signal::Transmittable
- Defined in:
- lib/tengine/job/edge.rb
Overview
Vertexとともにジョブネットを構成するグラフの「辺」を表すモデルTengine::Job::Jobnetにembeddedされます。
Defined Under Namespace
Classes: Closer, StatusError
Instance Method Summary
collapse
Instance Method Details
#accept_visitor(visitor) ⇒ Object
122
123
124
|
# File 'lib/tengine/job/edge.rb', line 122
def accept_visitor(visitor)
visitor.visit(self)
end
|
#alive? ⇒ Boolean
35
|
# File 'lib/tengine/job/edge.rb', line 35
def alive?; !!phase_entry[:alive]; end
|
#alive_or_closing? ⇒ Boolean
36
|
# File 'lib/tengine/job/edge.rb', line 36
def alive_or_closing?; alive? || closing?; end
|
#alive_or_closing_or_closed? ⇒ Boolean
37
|
# File 'lib/tengine/job/edge.rb', line 37
def alive_or_closing_or_closed?; alive? || closing? || closed?; end
|
#close(signal) ⇒ Object
111
112
113
114
115
116
|
# File 'lib/tengine/job/edge.rb', line 111
def close(signal)
case phase_key
when :active, :suspended, :keeping, :transmitting then
self.phase_key = :closing
end
end
|
#close_followings ⇒ Object
118
119
120
|
# File 'lib/tengine/job/edge.rb', line 118
def close_followings
accept_visitor(Tengine::Job::Edge::Closer.new)
end
|
#complete(signal) ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/tengine/job/edge.rb', line 87
def complete(signal)
case phase_key
when :transmitting then
self.phase_key = :transmitted
when :active, :closed then
when :suspended, :keeping then
raise Tengine::Job::Edge::StatusError, "#{self.class.name}#complete not available on #{phase_key.inspect} at #{self.inspect}"
end
end
|
#destination ⇒ Object
49
50
51
|
# File 'lib/tengine/job/edge.rb', line 49
def destination
owner.children.detect{|c| c.id == destination_id}
end
|
#inspect ⇒ Object
57
58
59
|
# File 'lib/tengine/job/edge.rb', line 57
def inspect
"#<#{self.class.name} #{name_for_message}>"
end
|
#name_for_message ⇒ Object
53
54
55
|
# File 'lib/tengine/job/edge.rb', line 53
def name_for_message
"edge(#{id.to_s}) from #{origin ? origin.name_path : 'no origin'} to #{destination ? destination.name_path : 'no destination'}"
end
|
#origin ⇒ Object
45
46
47
|
# File 'lib/tengine/job/edge.rb', line 45
def origin
owner.children.detect{|c| c.id == origin_id}
end
|
#phase_key=(phase_key) ⇒ Object
126
127
128
129
|
# File 'lib/tengine/job/edge.rb', line 126
def phase_key=(phase_key)
Tengine.logger.debug("edge phase changed. <#{self.id.to_s}> #{self.phase_name} -> #{Tengine::Job::Edge.phase_name_by_key(phase_key)}")
self.write_attribute(:phase_cd, Tengine::Job::Edge.phase_id_by_key(phase_key))
end
|
#reset(signal) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/tengine/job/edge.rb', line 99
def reset(signal)
if d = destination
if signal.execution.in_scope?(d)
self.phase_key = :active
d.reset(signal)
end
else
raise "destination not found: #{destination_id.inspect} from #{origin.inspect}"
end
end
|
#transmit(signal) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/tengine/job/edge.rb', line 62
def transmit(signal)
case phase_key
when :active then
d = destination
if signal.execution.in_scope?(d)
self.phase_key = :transmitting
signal.leave(self)
else
Tengine.logger.info("#{d.name_path} will not be executed, becauase it is out of execution scope.")
end
when :suspended then
self.phase_key = :keeping
when :closing then
self.phase_key = :closed
signal.paths << self
signal.with_paths_backup do
if destination.is_a?(Tengine::Job::Job)
destination.next_edges.first.transmit(signal)
else
signal.leave(self)
end
end
end
end
|