Class: Tengine::Job::Jobnet
- Inherits:
-
Job
- Object
- Job
- Tengine::Job::Jobnet
show all
- Includes:
- Core::SafeUpdatable, Core::SelectableAttr, ElementSelectorNotation
- Defined in:
- lib/tengine/job/jobnet.rb
Overview
ジョブの始端から終端までを持ち、VertexとEdgeを組み合わせてジョブネットを構成することができるVertex。自身もジョブネットを構成するVertexの一部として扱われる。
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.by_name(name) ⇒ Object
46
47
48
|
# File 'lib/tengine/job/jobnet.rb', line 46
def by_name(name)
where({:name => name}).first
end
|
Instance Method Details
#build_edges(auto_sequence, boot_job_names, redirections) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/tengine/job/jobnet.rb', line 97
def build_edges(auto_sequence, boot_job_names, redirections)
if self.children.length == 1
self.children.delete_all
return
end
if auto_sequence || boot_job_names.empty?
prepare_end
build_sequencial_edges
else
Builder.new(self, boot_job_names, redirections).process
end
end
|
#build_sequencial_edges ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/tengine/job/jobnet.rb', line 110
def build_sequencial_edges
self.edges.clear
current = nil
self.children.each do |child|
next if child.is_a?(Tengine::Job::Jobnet) && !!child.jobnet_type_entry[:alternative]
if current
edge = self.new_edge(current, child)
yield(edge) if block_given?
end
current = child
end
end
|
#chained_box? ⇒ Boolean
31
|
# File 'lib/tengine/job/jobnet.rb', line 31
def chained_box?; jobnet_type_entry[:chained_box]; end
|
#child_by_name(str) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/tengine/job/jobnet.rb', line 85
def child_by_name(str)
case str
when '..' then parent
when '.' then self
when 'start' then start_vertex
when 'end' then end_vertex
when 'finally' then finally_vertex
else
self.children.detect{|c| c.is_a?(Tengine::Job::Job) && (c.name == str)}
end
end
|
#end_vertex ⇒ Object
59
60
61
|
# File 'lib/tengine/job/jobnet.rb', line 59
def end_vertex
self.children.detect{|child| child.is_a?(Tengine::Job::End)}
end
|
#finally_vertex ⇒ Object
Also known as:
finally_jobnet
63
64
65
|
# File 'lib/tengine/job/jobnet.rb', line 63
def finally_vertex
self.children.detect{|child| child.is_a?(Tengine::Job::Jobnet) && (child.jobnet_type_key == :finally)}
end
|
#find_descendant(vertex_id) ⇒ Object
142
143
144
145
146
|
# File 'lib/tengine/job/jobnet.rb', line 142
def find_descendant(vertex_id)
vertex_id = String(vertex_id)
return nil if vertex_id == self.id.to_s
vertex(vertex_id)
end
|
#find_descendant_by_name_path(name_path) ⇒ Object
155
156
157
158
|
# File 'lib/tengine/job/jobnet.rb', line 155
def find_descendant_by_name_path(name_path)
return nil if name_path == self.name_path
vertex_by_name_path(name_path)
end
|
#find_descendant_edge(edge_id) ⇒ Object
Also known as:
edge
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/tengine/job/jobnet.rb', line 129
def find_descendant_edge(edge_id)
edge_id = String(edge_id)
visitor = Tengine::Job::Vertex::AnyVisitor.new do |vertex|
if vertex.respond_to?(:edges)
vertex.edges.detect{|edge| edge.id.to_s == edge_id}
else
nil
end
end
visitor.visit(self)
end
|
#new_edge(origin, destination) ⇒ Object
123
124
125
126
127
|
# File 'lib/tengine/job/jobnet.rb', line 123
def new_edge(origin, destination)
origin_id = origin.is_a?(Tengine::Job::Vertex) ? origin.id : origin
destination_id = destination.is_a?(Tengine::Job::Vertex) ? destination.id : destination
edges.new(:origin_id => origin_id, :destination_id => destination_id)
end
|
#prepare_end ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/tengine/job/jobnet.rb', line 73
def prepare_end
if self.children.last.is_a?(Tengine::Job::End)
_end = self.children.last
yield(_end) if block_given?
else
_end = Tengine::Job::End.new
yield(_end) if block_given?
self.children << _end
end
_end
end
|
#script_executable? ⇒ Boolean
51
52
53
|
# File 'lib/tengine/job/jobnet.rb', line 51
def script_executable?
!script.blank?
end
|
#start_vertex ⇒ Object
55
56
57
|
# File 'lib/tengine/job/jobnet.rb', line 55
def start_vertex
self.children.detect{|child| child.is_a?(Tengine::Job::Start)}
end
|
#vertex(vertex_id) ⇒ Object
148
149
150
151
152
153
|
# File 'lib/tengine/job/jobnet.rb', line 148
def vertex(vertex_id)
vertex_id = String(vertex_id)
return self if vertex_id == self.id.to_s
visitor = Tengine::Job::Vertex::AnyVisitor.new{|v| vertex_id == v.id.to_s ? v : nil }
visitor.visit(self)
end
|
#vertex_by_absolute_name_path(name_path) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/tengine/job/jobnet.rb', line 166
def vertex_by_absolute_name_path(name_path)
return self if name_path.to_s == self.name_path
visitor = Tengine::Job::Vertex::AnyVisitor.new do |vertex|
if name_path == (vertex.respond_to?(:name_path) ? vertex.name_path : nil)
vertex
else
nil
end
end
visitor.visit(self)
end
|
#vertex_by_name_path(name_path) ⇒ Object
160
161
162
163
164
|
# File 'lib/tengine/job/jobnet.rb', line 160
def vertex_by_name_path(name_path)
Tengine::Job::NamePath.absolute?(name_path) ?
root.vertex_by_absolute_name_path(name_path) :
vertex_by_relative_name_path(name_path)
end
|
#vertex_by_relative_name_path(name_path) ⇒ Object
178
179
180
181
182
|
# File 'lib/tengine/job/jobnet.rb', line 178
def vertex_by_relative_name_path(name_path)
head, tail = *name_path.split(Tengine::Job::NamePath::SEPARATOR, 2)
child = child_by_name(head)
tail ? child.vertex_by_relative_name_path(tail) : child
end
|
#with_start ⇒ Object
68
69
70
71
|
# File 'lib/tengine/job/jobnet.rb', line 68
def with_start
self.children << Tengine::Job::Start.new
self
end
|