flor 0.18.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +3 -0
- data/CREDITS.md +1 -0
- data/LICENSE.txt +1 -1
- data/Makefile +1 -1
- data/README.md +15 -1
- data/flor.gemspec +1 -2
- data/lib/flor.rb +2 -2
- data/lib/flor/colours.rb +5 -3
- data/lib/flor/conf.rb +1 -0
- data/lib/flor/core.rb +9 -8
- data/lib/flor/core/executor.rb +20 -16
- data/lib/flor/core/node.rb +1 -13
- data/lib/flor/core/procedure.rb +10 -1
- data/lib/flor/core/texecutor.rb +9 -2
- data/lib/flor/djan.rb +1 -0
- data/lib/flor/errors.rb +1 -0
- data/lib/flor/flor.rb +144 -15
- data/lib/flor/id.rb +1 -0
- data/lib/flor/log.rb +2 -1
- data/lib/flor/migrations/0001_tables.rb +1 -0
- data/lib/flor/migrations/0002_cunit_and_munit.rb +1 -0
- data/lib/flor/migrations/0003_timer_onid_bnid.rb +1 -0
- data/lib/flor/migrations/0004_trap_bnid.rb +1 -0
- data/lib/flor/migrations/0005_pointer_content.rb +1 -0
- data/lib/flor/parser.rb +19 -11
- data/lib/flor/pcore/_apply.rb +1 -0
- data/lib/flor/pcore/_arr.rb +1 -0
- data/lib/flor/pcore/_atom.rb +1 -0
- data/lib/flor/pcore/_att.rb +1 -0
- data/lib/flor/pcore/_coll.rb +1 -0
- data/lib/flor/pcore/_dmute.rb +1 -0
- data/lib/flor/pcore/_dol.rb +1 -0
- data/lib/flor/pcore/_dqs.rb +1 -0
- data/lib/flor/pcore/_dump.rb +1 -0
- data/lib/flor/pcore/_err.rb +1 -0
- data/lib/flor/pcore/_head.rb +1 -0
- data/lib/flor/pcore/_obj.rb +1 -0
- data/lib/flor/pcore/_pat_.rb +1 -0
- data/lib/flor/pcore/_pat_arr.rb +1 -0
- data/lib/flor/pcore/_pat_guard.rb +1 -0
- data/lib/flor/pcore/_pat_obj.rb +1 -0
- data/lib/flor/pcore/_pat_or.rb +1 -0
- data/lib/flor/pcore/_pat_regex.rb +1 -0
- data/lib/flor/pcore/_ref.rb +1 -0
- data/lib/flor/pcore/_rxs.rb +1 -0
- data/lib/flor/pcore/_skip.rb +1 -0
- data/lib/flor/pcore/_val.rb +1 -0
- data/lib/flor/pcore/all.rb +1 -0
- data/lib/flor/pcore/andor.rb +1 -0
- data/lib/flor/pcore/any.rb +1 -0
- data/lib/flor/pcore/apply.rb +1 -0
- data/lib/flor/pcore/arith.rb +1 -0
- data/lib/flor/pcore/array_qmark.rb +1 -0
- data/lib/flor/pcore/break.rb +1 -0
- data/lib/flor/pcore/case.rb +1 -0
- data/lib/flor/pcore/cmp.rb +1 -0
- data/lib/flor/pcore/collect.rb +2 -1
- data/lib/flor/pcore/cond.rb +1 -0
- data/lib/flor/pcore/cursor.rb +45 -3
- data/lib/flor/pcore/define.rb +1 -0
- data/lib/flor/pcore/detect.rb +1 -0
- data/lib/flor/pcore/do_return.rb +1 -0
- data/lib/flor/pcore/each.rb +1 -0
- data/lib/flor/pcore/echo.rb +1 -0
- data/lib/flor/pcore/empty.rb +1 -0
- data/lib/flor/pcore/fail.rb +1 -0
- data/lib/flor/pcore/filter.rb +1 -0
- data/lib/flor/pcore/find.rb +1 -0
- data/lib/flor/pcore/flatten.rb +1 -0
- data/lib/flor/pcore/for_each.rb +1 -0
- data/lib/flor/pcore/if.rb +1 -0
- data/lib/flor/pcore/includes.rb +1 -0
- data/lib/flor/pcore/inject.rb +1 -0
- data/lib/flor/pcore/iterator.rb +1 -0
- data/lib/flor/pcore/keys.rb +1 -0
- data/lib/flor/pcore/length.rb +1 -0
- data/lib/flor/pcore/loop.rb +1 -0
- data/lib/flor/pcore/map.rb +1 -0
- data/lib/flor/pcore/match.rb +1 -0
- data/lib/flor/pcore/matchr.rb +1 -0
- data/lib/flor/pcore/max.rb +1 -0
- data/lib/flor/pcore/merge.rb +1 -0
- data/lib/flor/pcore/move.rb +1 -0
- data/lib/flor/pcore/noeval.rb +1 -0
- data/lib/flor/pcore/noret.rb +1 -0
- data/lib/flor/pcore/not.rb +1 -0
- data/lib/flor/pcore/on.rb +4 -3
- data/lib/flor/pcore/on_cancel.rb +1 -0
- data/lib/flor/pcore/on_error.rb +1 -0
- data/lib/flor/pcore/push.rb +1 -0
- data/lib/flor/pcore/rand.rb +1 -0
- data/lib/flor/pcore/range.rb +1 -0
- data/lib/flor/pcore/reduce.rb +1 -0
- data/lib/flor/pcore/return.rb +1 -0
- data/lib/flor/pcore/reverse.rb +1 -0
- data/lib/flor/pcore/select.rb +1 -0
- data/lib/flor/pcore/sequence.rb +1 -0
- data/lib/flor/pcore/set.rb +1 -0
- data/lib/flor/pcore/shuffle.rb +1 -0
- data/lib/flor/pcore/slice.rb +1 -0
- data/lib/flor/pcore/sort.rb +1 -0
- data/lib/flor/pcore/sort_by.rb +1 -0
- data/lib/flor/pcore/split.rb +1 -0
- data/lib/flor/pcore/stall.rb +1 -0
- data/lib/flor/pcore/strings.rb +1 -0
- data/lib/flor/pcore/timestamp.rb +1 -0
- data/lib/flor/pcore/to_array.rb +1 -0
- data/lib/flor/pcore/twig.rb +1 -0
- data/lib/flor/pcore/type_of.rb +1 -0
- data/lib/flor/pcore/until.rb +1 -0
- data/lib/flor/punit/abort.rb +50 -0
- data/lib/flor/punit/c_collect.rb +1 -0
- data/lib/flor/punit/c_each.rb +19 -0
- data/lib/flor/punit/c_for_each.rb +2 -1
- data/lib/flor/punit/c_iterator.rb +1 -0
- data/lib/flor/punit/c_map.rb +1 -0
- data/lib/flor/punit/cancel.rb +1 -0
- data/lib/flor/punit/concurrence.rb +1 -0
- data/lib/flor/punit/cron.rb +1 -0
- data/lib/flor/punit/do_trap.rb +1 -0
- data/lib/flor/punit/every.rb +1 -0
- data/lib/flor/punit/graft.rb +1 -0
- data/lib/flor/punit/m_ram.rb +1 -0
- data/lib/flor/punit/on_timeout.rb +1 -0
- data/lib/flor/punit/part.rb +1 -0
- data/lib/flor/punit/schedule.rb +1 -0
- data/lib/flor/punit/signal.rb +1 -0
- data/lib/flor/punit/sleep.rb +1 -0
- data/lib/flor/punit/task.rb +1 -0
- data/lib/flor/punit/trace.rb +1 -0
- data/lib/flor/punit/trap.rb +10 -1
- data/lib/flor/to_string.rb +1 -0
- data/lib/flor/tools/env.rb +1 -0
- data/lib/flor/tools/shell.rb +1 -0
- data/lib/flor/tools/shell_out.rb +1 -0
- data/lib/flor/tt.rb +98 -0
- data/lib/flor/unit.rb +2 -0
- data/lib/flor/unit/caller.rb +152 -19
- data/lib/flor/unit/caller_jruby.rb +132 -0
- data/lib/flor/unit/dump.rb +36 -0
- data/lib/flor/unit/executor.rb +1 -0
- data/lib/flor/unit/ganger.rb +6 -12
- data/lib/flor/unit/hloader.rb +34 -7
- data/lib/flor/unit/hook.rb +3 -0
- data/lib/flor/unit/hooker.rb +32 -15
- data/lib/flor/unit/journal.rb +23 -0
- data/lib/flor/unit/loader.rb +102 -7
- data/lib/flor/unit/logger.rb +24 -5
- data/lib/flor/unit/models.rb +8 -1
- data/lib/flor/unit/models/execution.rb +51 -0
- data/lib/flor/unit/models/message.rb +1 -0
- data/lib/flor/unit/models/pointer.rb +1 -0
- data/lib/flor/unit/models/timer.rb +1 -0
- data/lib/flor/unit/models/trace.rb +1 -0
- data/lib/flor/unit/models/trap.rb +3 -2
- data/lib/flor/unit/scheduler.rb +35 -28
- data/lib/flor/unit/spooler.rb +1 -0
- data/lib/flor/unit/storage.rb +68 -44
- data/lib/flor/unit/taskers.rb +2 -1
- data/lib/flor/unit/waiter.rb +2 -1
- data/lib/flor/unit/wlist.rb +10 -8
- metadata +13 -10
data/lib/flor/unit/loader.rb
CHANGED
@@ -1,7 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
4
|
-
class
|
5
|
+
class CoreLoader
|
6
|
+
|
7
|
+
def shutdown
|
8
|
+
end
|
9
|
+
|
10
|
+
# Called to interpret require: confs from hooks and friends
|
11
|
+
#
|
12
|
+
def require(conf)
|
13
|
+
|
14
|
+
re = conf['require']
|
15
|
+
|
16
|
+
return unless re
|
17
|
+
|
18
|
+
::Kernel.require(
|
19
|
+
if path = conf['_path']
|
20
|
+
File.join(File.dirname(path), re)
|
21
|
+
else
|
22
|
+
re
|
23
|
+
end)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Loader < CoreLoader
|
5
28
|
|
6
29
|
# NB: tasker configuration entries start with "loa_"
|
7
30
|
|
@@ -12,10 +35,8 @@ module Flor
|
|
12
35
|
@cache = {}
|
13
36
|
@mutex = Mutex.new
|
14
37
|
|
15
|
-
@root = File.absolute_path(
|
16
|
-
|
17
|
-
|
18
|
-
def shutdown
|
38
|
+
@root = File.absolute_path(
|
39
|
+
@unit.conf['lod_path'] || @unit.conf['root'] || '.')
|
19
40
|
end
|
20
41
|
|
21
42
|
def variables(domain)
|
@@ -98,8 +119,8 @@ module Flor
|
|
98
119
|
.select { |pa, d| Flor.sub_domain?(d, domain) }
|
99
120
|
.sort_by { |pa, d| d.count('.') }
|
100
121
|
.collect { |pa, d|
|
101
|
-
eval(pa, {})
|
102
|
-
h['_path'] = pa + ":#{i}" } }
|
122
|
+
eval(pa, {})
|
123
|
+
.each_with_index { |h, i| h['_path'] = pa + ":#{i}" } }
|
103
124
|
.flatten(1)
|
104
125
|
end
|
105
126
|
|
@@ -109,8 +130,82 @@ module Flor
|
|
109
130
|
.collect { |h| Flor::Hook.new(@unit, exid, h) }
|
110
131
|
end
|
111
132
|
|
133
|
+
def domains(start=nil)
|
134
|
+
|
135
|
+
start ||= ''
|
136
|
+
|
137
|
+
Dir[File.join(@root, '**/*.{json,flo,flor,rb}')]
|
138
|
+
.collect { |pa| pa[@root.length..-1] }
|
139
|
+
.sort
|
140
|
+
.collect { |pa|
|
141
|
+
pa = pa[4..-1] if pa.match(/^\/usr\//)
|
142
|
+
case pa
|
143
|
+
when /\.flor?$/ then extract_flow_domain(pa)
|
144
|
+
when /\/lib\/hooks\// then extract_hook_domain(pa)
|
145
|
+
when /\/lib\/taskers\// then extract_tasker_domain(pa)
|
146
|
+
when /\/etc\/variables\// then extract_variable_domain(pa)
|
147
|
+
else nil
|
148
|
+
end }
|
149
|
+
.compact
|
150
|
+
.select { |pa| pa.length > 1 }
|
151
|
+
.collect { |pa|
|
152
|
+
pa = pa[1..-1] if pa[0, 1] == '/'
|
153
|
+
pa = pa[0..-2] if pa.match(/\/$/)
|
154
|
+
pa.gsub('/', '.') }
|
155
|
+
.sort
|
156
|
+
.uniq
|
157
|
+
.select { |dm| Flor.sub_domain?(start, dm) }
|
158
|
+
end
|
159
|
+
|
160
|
+
def definitions(start=nil)
|
161
|
+
|
162
|
+
start ||= ''
|
163
|
+
|
164
|
+
Dir[File.join(@root, '**/*.{flo,flor}')]
|
165
|
+
.collect { |pa| pa[@root.length..-1] }
|
166
|
+
.collect { |pa| pa.gsub(/\A\/usr\//, '/') }
|
167
|
+
.collect { |pa| pa.gsub(/\/lib\/(sub)?flows\//, '/') }
|
168
|
+
.collect { |pa| pa.gsub(/\.flor?\z/, '') }
|
169
|
+
.collect { |pa| pa.gsub(/\//, '.') }
|
170
|
+
.collect { |pa| pa.gsub(/\A\./, '') }
|
171
|
+
.sort
|
172
|
+
.select { |pa| Flor.sub_domain?(start, pa) }
|
173
|
+
end
|
174
|
+
|
112
175
|
protected
|
113
176
|
|
177
|
+
def extract_flow_domain(pa)
|
178
|
+
#o = pa
|
179
|
+
pa
|
180
|
+
.gsub(/\/lib\/(sub)?flows\//, '/')
|
181
|
+
.split('/')[0..-2].join('/')
|
182
|
+
#.tap { |x| p 'flow:' + o + ':' + x }
|
183
|
+
end
|
184
|
+
def extract_hook_domain(pa)
|
185
|
+
#o = pa
|
186
|
+
pa
|
187
|
+
.gsub(/\/lib\/hooks\//, '/')
|
188
|
+
.gsub(/\/(dot|hooks)\.(json|rb)$/, '/')
|
189
|
+
.gsub(/\.(json|rb)$/, '')
|
190
|
+
#.tap { |x| p 'hook:' + o + ':' + x }
|
191
|
+
end
|
192
|
+
def extract_tasker_domain(pa)
|
193
|
+
#o = pa
|
194
|
+
pa
|
195
|
+
.gsub(/\/lib\/taskers\//, '/')
|
196
|
+
.gsub(/\/[^\/]+\/(dot|flor|tasker)\.(json|rb)$/, '/')
|
197
|
+
.gsub(/\.(json|rb)$/, '')
|
198
|
+
#.tap { |x| p 'tasker: ' + o + ': ' + x }
|
199
|
+
end
|
200
|
+
def extract_variable_domain(pa)
|
201
|
+
#o = pa
|
202
|
+
pa
|
203
|
+
.gsub(/\/etc\/variables\//, '/')
|
204
|
+
.gsub(/\/(dot|flor)\.(json|rb)$/, '/')
|
205
|
+
.gsub(/\.(json|rb)$/, '')
|
206
|
+
#.tap { |x| p 'variable: ' + o + ': ' + x }
|
207
|
+
end
|
208
|
+
|
114
209
|
def split_dn(domain, name)
|
115
210
|
|
116
211
|
if name
|
data/lib/flor/unit/logger.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
@@ -62,17 +63,24 @@ module Flor
|
|
62
63
|
n = Time.now.utc
|
63
64
|
stp = Flor.tstamp(n)
|
64
65
|
|
66
|
+
dbi =
|
67
|
+
case @unit.storage.db.to_s
|
68
|
+
when /SQLite/ then @unit.storage.db.uri
|
69
|
+
else ''
|
70
|
+
end
|
71
|
+
dbi = ' ' + dbi if dbi.length > 0
|
72
|
+
|
65
73
|
txt = elts.collect(&:to_s).join(' ')
|
66
74
|
err = elts.find { |e| e.is_a?(Exception) }
|
67
75
|
|
68
|
-
|
76
|
+
head = "#{stp} #{@uni}#{dbi} #{lvl} "
|
69
77
|
|
70
78
|
if err
|
71
|
-
dig = lvl[0, 1] + Digest::MD5.hexdigest(
|
72
|
-
@out.puts(
|
79
|
+
dig = lvl[0, 1] + Digest::MD5.hexdigest(head + txt)[0, 4]
|
80
|
+
@out.puts(head + dig + ' ' + txt)
|
73
81
|
err.backtrace.each { |lin| @out.puts(" #{dig} #{@uni} #{lin}") }
|
74
82
|
else
|
75
|
-
@out.puts(
|
83
|
+
@out.puts(head + txt)
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
@@ -113,7 +121,18 @@ module Flor
|
|
113
121
|
#
|
114
122
|
msg = summarize_blob(msg)
|
115
123
|
|
116
|
-
|
124
|
+
msg = "#{_c.dg}#{msg}"
|
125
|
+
msg = msg.gsub(/\b(INSERT|UPDATE)\b/) { |m| "#{_c.rs}#{m}#{_c.dg}" }
|
126
|
+
|
127
|
+
tim = Time.now.utc.strftime('%T.%L') # HH:MM:SS.123
|
128
|
+
dbi = @unit.storage.db.object_id.to_s(16)
|
129
|
+
tid = Thread.current.object_id.to_s(16)
|
130
|
+
lvl = level.upcase
|
131
|
+
|
132
|
+
@out.puts(
|
133
|
+
"#{_c.blg}sto#{_c.rs} " +
|
134
|
+
"#{tim} #{_c.dg}db#{dbi} th#{tid} " +
|
135
|
+
"#{_c.rs}#{lvl}#{_c.rs} #{msg}#{_c.rs}")
|
117
136
|
end
|
118
137
|
|
119
138
|
def size_to_s(s)
|
data/lib/flor/unit/models.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
@@ -92,6 +93,12 @@ module Flor
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
96
|
+
alias to_dump_h to_h
|
97
|
+
#
|
98
|
+
# Downsteam, #to_h answers are more complete, more standalone
|
99
|
+
# whereas, #to_dump_h answers are more compact (see florist).
|
100
|
+
# For now, they're just the same, it specializes downstream.
|
101
|
+
|
95
102
|
class << self
|
96
103
|
|
97
104
|
def from_h(h)
|
@@ -135,7 +142,7 @@ module Flor
|
|
135
142
|
|
136
143
|
@models[key] ||=
|
137
144
|
parent_module.const_set(
|
138
|
-
"#{c}#{
|
145
|
+
"#{c}#{self.object_id.to_s.gsub('-', 'M')}",
|
139
146
|
Class.new(parent_module.const_get(c)) do
|
140
147
|
self.dataset = s.db["#{table_prefix}#{key}".to_sym]
|
141
148
|
self.unit = s.unit
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
@@ -98,6 +99,56 @@ module Flor
|
|
98
99
|
h
|
99
100
|
end
|
100
101
|
|
102
|
+
def lookup_nodes(query, opts={})
|
103
|
+
|
104
|
+
@node_index ||= nodes
|
105
|
+
.sort_by { |k, _| k }
|
106
|
+
.inject({}) { |h, (k, v)|
|
107
|
+
#
|
108
|
+
# nid => [ node ]
|
109
|
+
#
|
110
|
+
h[k] = [ v ]
|
111
|
+
#
|
112
|
+
# code => [ node0, node1, ... ]
|
113
|
+
#
|
114
|
+
t =
|
115
|
+
(lookup_tree(v['parent'])[1][Flor.child_id(v['nid'])] rescue nil) ||
|
116
|
+
lookup_tree(v['nid'])
|
117
|
+
s = Flor.tree_to_flor(t, chop: true)
|
118
|
+
(h[s] ||= []) << v
|
119
|
+
#
|
120
|
+
# tag => [ node0, node1, ... ]
|
121
|
+
#
|
122
|
+
ts = v['tags']
|
123
|
+
ts.each { |t| (h[t] ||= []) << v } if ts
|
124
|
+
#
|
125
|
+
h }
|
126
|
+
|
127
|
+
@node_index
|
128
|
+
.select { |k, v|
|
129
|
+
case query
|
130
|
+
when Regexp then k.match(query)
|
131
|
+
else k == query
|
132
|
+
end }
|
133
|
+
.values
|
134
|
+
.flatten(1)
|
135
|
+
end
|
136
|
+
|
137
|
+
def lookup_node(query, opts={})
|
138
|
+
|
139
|
+
lookup_nodes(query, opts).first
|
140
|
+
end
|
141
|
+
|
142
|
+
def lookup_nids(query, opts={})
|
143
|
+
|
144
|
+
lookup_nodes(query, opts).collect { |n| n['nid'] }
|
145
|
+
end
|
146
|
+
|
147
|
+
def lookup_nid(query, opts={})
|
148
|
+
|
149
|
+
lookup_node(query, opts)['nid']
|
150
|
+
end
|
151
|
+
|
101
152
|
class << self
|
102
153
|
|
103
154
|
def by_status(s)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
@@ -124,7 +125,7 @@ module Flor
|
|
124
125
|
'exid' => self.exid,
|
125
126
|
'nid' => self.nid,
|
126
127
|
'type' => 'trap',
|
127
|
-
'trap' =>
|
128
|
+
'trap' => to_trap_h,
|
128
129
|
'trap_id' => self.id,
|
129
130
|
'message' => msg,
|
130
131
|
'sm' => message['m'] }
|
@@ -133,7 +134,7 @@ module Flor
|
|
133
134
|
#'dbg' => xx }
|
134
135
|
end
|
135
136
|
|
136
|
-
def
|
137
|
+
def to_trap_h
|
137
138
|
|
138
139
|
values
|
139
140
|
.inject({}) { |h, (k, v)| h[k.to_s] = v if k != :content; h }
|
data/lib/flor/unit/scheduler.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
3
|
module Flor
|
3
4
|
|
@@ -9,6 +10,7 @@ module Flor
|
|
9
10
|
attr_reader :logger
|
10
11
|
|
11
12
|
attr_reader :thread_status
|
13
|
+
attr_reader :last_queued_message_id
|
12
14
|
|
13
15
|
attr_reader :archive
|
14
16
|
|
@@ -222,7 +224,8 @@ module Flor
|
|
222
224
|
|
223
225
|
def queue(message, opts={})
|
224
226
|
|
225
|
-
@
|
227
|
+
@last_queued_message_id =
|
228
|
+
@storage.put_message(message)
|
226
229
|
|
227
230
|
if opts[:wait]
|
228
231
|
wait(message['exid'], opts)
|
@@ -356,9 +359,13 @@ module Flor
|
|
356
359
|
) unless nid
|
357
360
|
|
358
361
|
fail ArgumentError.new(
|
359
|
-
"cannot add iteration to
|
362
|
+
"cannot add iteration to node #{nid.inspect} not present in tree"
|
360
363
|
) unless exe.lookup_tree(nid)
|
361
364
|
|
365
|
+
fail ArgumentError.new(
|
366
|
+
"cannot add iteration to node #{nid.inspect} not present in execution"
|
367
|
+
) unless exe.nodes.has_key?(nid)
|
368
|
+
|
362
369
|
queue(msg, opts)
|
363
370
|
end
|
364
371
|
alias add_iteration add_iterations
|
@@ -434,16 +441,14 @@ module Flor
|
|
434
441
|
#
|
435
442
|
# unit.dump() { |h| ... } # modify the has right before it's turned to JSON
|
436
443
|
#
|
444
|
+
# unit.dump(hash: true) # returns the hash (instead of JSONing it)
|
445
|
+
#
|
437
446
|
def dump(io=nil, opts=nil, &block)
|
438
447
|
|
439
448
|
io, opts = nil, io if io.is_a?(Hash)
|
440
449
|
opts ||= {}
|
441
450
|
|
442
|
-
|
443
|
-
#
|
444
|
-
exis = o[:exid]
|
445
|
-
doms = o[:domain]
|
446
|
-
sdms = o[:strict_domain] || o[:sdomain]
|
451
|
+
exis, doms, sdms = extract_dump_and_load_filters(opts)
|
447
452
|
#
|
448
453
|
filter = lambda { |q|
|
449
454
|
q = q.where(
|
@@ -458,25 +463,25 @@ module Flor
|
|
458
463
|
domain: sdms) if sdms
|
459
464
|
q }
|
460
465
|
|
461
|
-
|
466
|
+
hash =
|
462
467
|
storage.db.transaction {
|
463
|
-
[ filter[executions].collect(&:to_h),
|
464
|
-
filter[timers].collect(&:to_h),
|
465
|
-
filter[traps].collect(&:to_h),
|
466
|
-
filter[pointers].collect(&:to_h) ] }
|
467
468
|
|
468
|
-
|
469
|
+
h = {
|
470
|
+
timestamp: Flor.tstamp,
|
471
|
+
executions: filter[executions].collect(&:to_h),
|
472
|
+
timers: filter[timers].collect(&:to_h),
|
473
|
+
traps: filter[traps].collect(&:to_h),
|
474
|
+
pointers: filter[pointers].collect(&:to_h) }
|
475
|
+
|
476
|
+
block.call(h) if block
|
469
477
|
|
470
|
-
|
471
|
-
timestamp: Flor.tstamp,
|
472
|
-
executions: exs,
|
473
|
-
timers: tms,
|
474
|
-
traps: tps,
|
475
|
-
pointers: pts }
|
478
|
+
h }
|
476
479
|
|
477
|
-
|
480
|
+
return hash if opts[:hash] || opts[:h]
|
481
|
+
|
482
|
+
o = io ? io : StringIO.new
|
478
483
|
|
479
|
-
JSON.dump(
|
484
|
+
JSON.dump(hash, o)
|
480
485
|
|
481
486
|
io ? io : o.string
|
482
487
|
end
|
@@ -507,12 +512,7 @@ module Flor
|
|
507
512
|
mks = DUMP_KEYS - h.keys
|
508
513
|
fail Flor::FlorError.new("missing keys #{mks.inspect}") if mks.any?
|
509
514
|
|
510
|
-
|
511
|
-
#
|
512
|
-
exis = o[:exid]
|
513
|
-
doms = o[:domain]
|
514
|
-
sdms = o[:strict_domain] || o[:sdomain]
|
515
|
-
#
|
515
|
+
exis, doms, sdms = extract_dump_and_load_filters(opts)
|
516
516
|
doms = doms.collect { |d| /\A#{d}(\.#{Flor::NAME_REX})*\z/ } if doms
|
517
517
|
|
518
518
|
counts = { executions: 0, timers: 0, traps: 0, pointers: 0, total: 0 }
|
@@ -541,7 +541,7 @@ module Flor
|
|
541
541
|
cla.import(cols, rows) if rows.any?
|
542
542
|
end
|
543
543
|
|
544
|
-
block.call(h) if block
|
544
|
+
block.call(h, counts) if block
|
545
545
|
end
|
546
546
|
|
547
547
|
counts
|
@@ -549,6 +549,13 @@ module Flor
|
|
549
549
|
|
550
550
|
protected
|
551
551
|
|
552
|
+
def extract_dump_and_load_filters(opts)
|
553
|
+
|
554
|
+
o = lambda { |k| v = opts[k] || opts["#{k}s".to_sym]; v ? Array(v) : nil }
|
555
|
+
|
556
|
+
[ o[:exid], o[:domain], o[:strict_domain] || o[:sdomain] ]
|
557
|
+
end
|
558
|
+
|
552
559
|
def tick
|
553
560
|
|
554
561
|
t0 = Time.now
|