Class: Flor::Execution
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from FlorModel
#data, from_h, #node, #payload, #refresh, #storage, #unit
Class Method Details
.by_status(s) ⇒ Object
203
204
205
206
|
# File 'lib/flor/unit/models/execution.rb', line 203
def by_status(s)
where(status: s)
end
|
.by_tag(name) ⇒ Object
213
214
215
216
217
218
219
220
221
|
# File 'lib/flor/unit/models/execution.rb', line 213
def by_tag(name)
_exids = db[:flor_pointers]
.where(type: 'tag', name: name, value: nil)
.select(:exid)
.distinct
where(status: 'active', exid: _exids)
end
|
.by_tasker(name, taskname = :no) ⇒ Object
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/flor/unit/models/execution.rb', line 243
def by_tasker(name, taskname=:no)
w = { type: 'tasker', name: name }
w[:value] = taskname if taskname != :no
_exids = db[:flor_pointers]
.where(w)
.select(:exid)
.distinct
where(status: 'active', exid: _exids)
end
|
.by_var(name, value = :no) ⇒ Object
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/flor/unit/models/execution.rb', line 223
def by_var(name, value=:no)
w = { type: 'var', name: name }
case value; when nil
w[:value] = nil
when :no
else
w[:value] = value.to_s
end
_exids = db[:flor_pointers]
.where(w)
.select(:exid)
.distinct
where(status: 'active', exid: _exids)
end
|
.terminated ⇒ Object
208
209
210
211
|
# File 'lib/flor/unit/models/execution.rb', line 208
def terminated
by_status('terminated')
end
|
Instance Method Details
#closing_messages ⇒ Object
46
|
# File 'lib/flor/unit/models/execution.rb', line 46
def closing_messages; data['closing_messages']; end
|
#execution(reload = false) ⇒ Object
48
|
# File 'lib/flor/unit/models/execution.rb', line 48
def execution(reload=false); self; end
|
#failed? ⇒ Boolean
58
59
60
61
62
|
# File 'lib/flor/unit/models/execution.rb', line 58
def failed?
!! nodes.values
.find { |n| n['failure'] && n['status'] != 'triggered-on-error' }
end
|
#failed_nodes ⇒ Object
64
65
66
67
68
|
# File 'lib/flor/unit/models/execution.rb', line 64
def failed_nodes
nodes.values
.select { |n| n['failure'] && n['status'] != 'triggered-on-error' }
end
|
#full_tree ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/flor/unit/models/execution.rb', line 70
def full_tree
nids = sorted_nids
nid0 = nids.shift
return nil unless nid0
tree = Flor.dup(nodes[nid0]['tree'])
nids.each { |nid|
next unless nid.split('_', 2).first == nid0
replace_sub_tree(tree, nid, nodes[nid]['tree']) }
tree
end
|
#lookup_nid(query, opts = {}) ⇒ Object
172
173
174
175
|
# File 'lib/flor/unit/models/execution.rb', line 172
def lookup_nid(query, opts={})
lookup_node(query, opts)['nid']
end
|
#lookup_nids(query, opts = {}) ⇒ Object
167
168
169
170
|
# File 'lib/flor/unit/models/execution.rb', line 167
def lookup_nids(query, opts={})
lookup_nodes(query, opts).collect { |n| n['nid'] }
end
|
#lookup_node(query, opts = {}) ⇒ Object
162
163
164
165
|
# File 'lib/flor/unit/models/execution.rb', line 162
def lookup_node(query, opts={})
lookup_nodes(query, opts).first
end
|
#lookup_nodes(query, opts = {}) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# File 'lib/flor/unit/models/execution.rb', line 127
def lookup_nodes(query, opts={})
@node_index ||= nodes
.sort_by { |k, _| k }
.inject({}) { |h, (k, v)|
h[k] = [ v ]
t =
(lookup_tree(v['parent'])[1][Flor.child_id(v['nid'])] rescue nil) ||
lookup_tree(v['nid'])
s = Flor.tree_to_flor(t, chop: true)
(h[s] ||= []) << v
ts = v['tags']
ts.each { |t| (h[t] ||= []) << v } if ts
h }
@node_index
.select { |k, v|
case query
when Regexp then k.match(query)
else k == query
end }
.values
.flatten(1)
end
|
#lookup_tree(nid) ⇒ Object
86
87
88
89
90
|
# File 'lib/flor/unit/models/execution.rb', line 86
def lookup_tree(nid)
Flor::Node.new(self.data, nodes[nid], nil)
.lookup_tree(nid)
end
|
#lowest_node ⇒ Object
41
42
43
44
|
# File 'lib/flor/unit/models/execution.rb', line 41
def lowest_node
nodes[sorted_nids.first]
end
|
#nodes ⇒ Object
create_table :flor_executions do
primary_key :id, type: :Integer
String :domain, null: false
String :exid, null: false
File :content String :status, null: false String :ctime, null: false
String :mtime, null: false
String :cunit
String :munit
index :exid
end
22
|
# File 'lib/flor/unit/models/execution.rb', line 22
def nodes; data['nodes']; end
|
#sorted_nids ⇒ Object
Returns the nids, the lower in the tree, the earlier in the returned array.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/flor/unit/models/execution.rb', line 29
def sorted_nids
nodes.keys
.inject([]) { |a, nid|
l = nid.split('_').length
(a[l] ||= []) << nid
a }
.compact
.collect(&:sort)
.flatten(1)
end
|
50
51
52
53
54
55
56
|
# File 'lib/flor/unit/models/execution.rb', line 50
def tags
data['nodes'].values.inject([]) do |a, n|
if ts = n['tags']; a.concat(ts); end
a
end
end
|
#to_h ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/flor/unit/models/execution.rb', line 97
def to_h
h = super
h[:size] = self[:content].size
m = h[:meta] = {}
cs = m[:counts] = {}
is = m[:nids] = { tasks: [], failures: [] }
cs[:failures] = 0
cs[:tasks] = 0
cs[:nodes] = nodes.count
nodes.each do |k, v|
if v['task']
cs[:tasks] += 1
is[:tasks] << k
end
if v['failure']
cs[:failures] += 1
is[:failures] << k
end
end
h[:tree] = full_tree
h
end
|
#zero_node ⇒ Object
24
|
# File 'lib/flor/unit/models/execution.rb', line 24
def zero_node; nodes['0']; end
|
#zero_variables ⇒ Object
92
93
94
95
|
# File 'lib/flor/unit/models/execution.rb', line 92
def zero_variables
zero_node['vars']
end
|