flor 0.18.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +29 -0
  3. data/CREDITS.md +1 -0
  4. data/LICENSE.txt +1 -1
  5. data/Makefile +1 -1
  6. data/README.md +16 -2
  7. data/flor.gemspec +1 -2
  8. data/lib/flor.rb +3 -2
  9. data/lib/flor/colours.rb +5 -3
  10. data/lib/flor/conf.rb +1 -0
  11. data/lib/flor/core.rb +9 -8
  12. data/lib/flor/core/executor.rb +20 -16
  13. data/lib/flor/core/node.rb +1 -13
  14. data/lib/flor/core/procedure.rb +10 -1
  15. data/lib/flor/core/texecutor.rb +35 -3
  16. data/lib/flor/djan.rb +1 -0
  17. data/lib/flor/errors.rb +1 -0
  18. data/lib/flor/flor.rb +172 -26
  19. data/lib/flor/id.rb +5 -1
  20. data/lib/flor/log.rb +14 -8
  21. data/lib/flor/migrations/0001_tables.rb +1 -0
  22. data/lib/flor/migrations/0002_cunit_and_munit.rb +1 -0
  23. data/lib/flor/migrations/0003_timer_onid_bnid.rb +1 -0
  24. data/lib/flor/migrations/0004_trap_bnid.rb +1 -0
  25. data/lib/flor/migrations/0005_pointer_content.rb +1 -0
  26. data/lib/flor/parser.rb +19 -11
  27. data/lib/flor/pcore/_apply.rb +1 -0
  28. data/lib/flor/pcore/_arr.rb +1 -0
  29. data/lib/flor/pcore/_atom.rb +1 -0
  30. data/lib/flor/pcore/_att.rb +1 -0
  31. data/lib/flor/pcore/_coll.rb +1 -0
  32. data/lib/flor/pcore/_dmute.rb +1 -0
  33. data/lib/flor/pcore/_dol.rb +1 -0
  34. data/lib/flor/pcore/_dqs.rb +1 -0
  35. data/lib/flor/pcore/_dump.rb +1 -0
  36. data/lib/flor/pcore/_err.rb +1 -0
  37. data/lib/flor/pcore/_head.rb +1 -0
  38. data/lib/flor/pcore/_obj.rb +1 -0
  39. data/lib/flor/pcore/_pat_.rb +1 -0
  40. data/lib/flor/pcore/_pat_arr.rb +1 -0
  41. data/lib/flor/pcore/_pat_guard.rb +1 -0
  42. data/lib/flor/pcore/_pat_obj.rb +1 -0
  43. data/lib/flor/pcore/_pat_or.rb +1 -0
  44. data/lib/flor/pcore/_pat_regex.rb +1 -0
  45. data/lib/flor/pcore/_ref.rb +1 -0
  46. data/lib/flor/pcore/_rxs.rb +1 -0
  47. data/lib/flor/pcore/_skip.rb +1 -0
  48. data/lib/flor/pcore/_val.rb +1 -0
  49. data/lib/flor/pcore/all.rb +1 -0
  50. data/lib/flor/pcore/andor.rb +1 -0
  51. data/lib/flor/pcore/any.rb +1 -0
  52. data/lib/flor/pcore/apply.rb +1 -0
  53. data/lib/flor/pcore/arith.rb +1 -0
  54. data/lib/flor/pcore/array_qmark.rb +1 -0
  55. data/lib/flor/pcore/break.rb +1 -0
  56. data/lib/flor/pcore/case.rb +1 -0
  57. data/lib/flor/pcore/cmp.rb +1 -0
  58. data/lib/flor/pcore/collect.rb +2 -1
  59. data/lib/flor/pcore/cond.rb +1 -0
  60. data/lib/flor/pcore/cursor.rb +45 -3
  61. data/lib/flor/pcore/define.rb +1 -0
  62. data/lib/flor/pcore/detect.rb +1 -0
  63. data/lib/flor/pcore/do_return.rb +1 -0
  64. data/lib/flor/pcore/each.rb +1 -0
  65. data/lib/flor/pcore/echo.rb +1 -0
  66. data/lib/flor/pcore/empty.rb +1 -0
  67. data/lib/flor/pcore/fail.rb +1 -0
  68. data/lib/flor/pcore/filter.rb +1 -0
  69. data/lib/flor/pcore/find.rb +1 -0
  70. data/lib/flor/pcore/flatten.rb +1 -0
  71. data/lib/flor/pcore/for_each.rb +1 -0
  72. data/lib/flor/pcore/if.rb +1 -0
  73. data/lib/flor/pcore/includes.rb +1 -0
  74. data/lib/flor/pcore/inject.rb +1 -0
  75. data/lib/flor/pcore/iterator.rb +1 -0
  76. data/lib/flor/pcore/keys.rb +1 -0
  77. data/lib/flor/pcore/length.rb +1 -0
  78. data/lib/flor/pcore/loop.rb +1 -0
  79. data/lib/flor/pcore/map.rb +1 -0
  80. data/lib/flor/pcore/match.rb +1 -0
  81. data/lib/flor/pcore/matchr.rb +1 -0
  82. data/lib/flor/pcore/max.rb +1 -0
  83. data/lib/flor/pcore/merge.rb +1 -0
  84. data/lib/flor/pcore/move.rb +1 -0
  85. data/lib/flor/pcore/noeval.rb +1 -0
  86. data/lib/flor/pcore/noret.rb +1 -0
  87. data/lib/flor/pcore/not.rb +1 -0
  88. data/lib/flor/pcore/on.rb +4 -3
  89. data/lib/flor/pcore/on_cancel.rb +1 -0
  90. data/lib/flor/pcore/on_error.rb +1 -0
  91. data/lib/flor/pcore/push.rb +1 -0
  92. data/lib/flor/pcore/rand.rb +1 -0
  93. data/lib/flor/pcore/range.rb +1 -0
  94. data/lib/flor/pcore/reduce.rb +1 -0
  95. data/lib/flor/pcore/return.rb +1 -0
  96. data/lib/flor/pcore/reverse.rb +1 -0
  97. data/lib/flor/pcore/select.rb +1 -0
  98. data/lib/flor/pcore/sequence.rb +1 -0
  99. data/lib/flor/pcore/set.rb +1 -0
  100. data/lib/flor/pcore/shuffle.rb +1 -0
  101. data/lib/flor/pcore/slice.rb +1 -0
  102. data/lib/flor/pcore/sort.rb +1 -0
  103. data/lib/flor/pcore/sort_by.rb +1 -0
  104. data/lib/flor/pcore/split.rb +1 -0
  105. data/lib/flor/pcore/stall.rb +1 -0
  106. data/lib/flor/pcore/strings.rb +1 -0
  107. data/lib/flor/pcore/timestamp.rb +1 -0
  108. data/lib/flor/pcore/to_array.rb +1 -0
  109. data/lib/flor/pcore/twig.rb +1 -0
  110. data/lib/flor/pcore/type_of.rb +1 -0
  111. data/lib/flor/pcore/until.rb +1 -0
  112. data/lib/flor/punit/abort.rb +50 -0
  113. data/lib/flor/punit/c_collect.rb +1 -0
  114. data/lib/flor/punit/c_each.rb +19 -0
  115. data/lib/flor/punit/c_for_each.rb +2 -1
  116. data/lib/flor/punit/c_iterator.rb +2 -1
  117. data/lib/flor/punit/c_map.rb +1 -0
  118. data/lib/flor/punit/cancel.rb +1 -0
  119. data/lib/flor/punit/concurrence.rb +7 -5
  120. data/lib/flor/punit/cron.rb +1 -0
  121. data/lib/flor/punit/do_trap.rb +1 -0
  122. data/lib/flor/punit/every.rb +1 -0
  123. data/lib/flor/punit/graft.rb +1 -0
  124. data/lib/flor/punit/{m_ram.rb → m_receive_and_merge.rb} +5 -4
  125. data/lib/flor/punit/on_timeout.rb +1 -0
  126. data/lib/flor/punit/part.rb +1 -0
  127. data/lib/flor/punit/schedule.rb +1 -0
  128. data/lib/flor/punit/signal.rb +1 -0
  129. data/lib/flor/punit/sleep.rb +1 -0
  130. data/lib/flor/punit/task.rb +1 -0
  131. data/lib/flor/punit/trace.rb +1 -0
  132. data/lib/flor/punit/trap.rb +10 -1
  133. data/lib/flor/to_string.rb +1 -0
  134. data/lib/flor/tools/env.rb +1 -0
  135. data/lib/flor/tools/firb.rb +33 -0
  136. data/lib/flor/tools/shell.rb +13 -3
  137. data/lib/flor/tools/shell_out.rb +1 -0
  138. data/lib/flor/tt.rb +98 -0
  139. data/lib/flor/unit.rb +3 -0
  140. data/lib/flor/unit/caller.rb +158 -23
  141. data/lib/flor/unit/caller_jruby.rb +133 -0
  142. data/lib/flor/unit/dump.rb +36 -0
  143. data/lib/flor/unit/executor.rb +19 -13
  144. data/lib/flor/unit/ganger.rb +9 -12
  145. data/lib/flor/unit/gangers.rb +125 -0
  146. data/lib/flor/unit/hloader.rb +34 -7
  147. data/lib/flor/unit/hook.rb +3 -0
  148. data/lib/flor/unit/hooker.rb +32 -15
  149. data/lib/flor/unit/journal.rb +23 -0
  150. data/lib/flor/unit/loader.rb +142 -15
  151. data/lib/flor/unit/logger.rb +35 -7
  152. data/lib/flor/unit/models.rb +8 -1
  153. data/lib/flor/unit/models/execution.rb +51 -0
  154. data/lib/flor/unit/models/message.rb +6 -0
  155. data/lib/flor/unit/models/pointer.rb +21 -1
  156. data/lib/flor/unit/models/timer.rb +1 -0
  157. data/lib/flor/unit/models/trace.rb +1 -0
  158. data/lib/flor/unit/models/trap.rb +3 -2
  159. data/lib/flor/unit/scheduler.rb +51 -36
  160. data/lib/flor/unit/spooler.rb +1 -0
  161. data/lib/flor/unit/storage.rb +113 -84
  162. data/lib/flor/unit/taskers.rb +70 -1
  163. data/lib/flor/unit/waiter.rb +22 -17
  164. data/lib/flor/unit/wlist.rb +19 -8
  165. metadata +16 -11
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -28,6 +29,29 @@ module Flor
28
29
  alias task_name taskname
29
30
 
30
31
  def vars; @message['vars']; end
32
+ alias variables vars
33
+
34
+ def set_payload(h)
35
+ fail TypeError.new("not a hash but a #{fs.class}") unless h.is_a?(Hash)
36
+ @message['payload'] = h
37
+ end
38
+ alias set_fields set_payload
39
+
40
+ def set_vars(h)
41
+ fail TypeError.new("not a hash but a #{fs.class}") unless h.is_a?(Hash)
42
+ @message['vars'] = h
43
+ end
44
+ alias set_variables set_vars
45
+
46
+ #def merge_into_payload(h)
47
+ # @message['payload'].merge(h)
48
+ #end
49
+ #alias merge_into_fields merge_into_payload
50
+ #def merge_into_vars(h)
51
+ # @message['vars'].merge(h)
52
+ #end
53
+ #
54
+ # no for now, payload.merge(h) and vars.merge(h) do suffice
31
55
 
32
56
  def execution
33
57
 
@@ -88,7 +112,7 @@ module Flor
88
112
  return m if Flor.is_exid?(exid) && Flor.is_nid?(nid) && pl.is_a?(Hash)
89
113
 
90
114
  m = Flor.to_string_keyed_hash(m)
91
- h = Flor.dup(@message)
115
+ h = Flor.dup_message(@message)
92
116
  ks = m.keys
93
117
 
94
118
  if ks == [ 'payload' ]
@@ -111,5 +135,50 @@ module Flor
111
135
  h
112
136
  end
113
137
  end
138
+
139
+ # A BasicTasker with stages (pre / on / post)
140
+ #
141
+ class StagedBasicTasker < BasicTasker
142
+
143
+ def call_task
144
+
145
+ call_one_of(:pre_task)
146
+ call_one_of(:on_task, :task)
147
+ end
148
+
149
+ def call_detask
150
+
151
+ call_one_of(:pre_detask, :pre_cancel)
152
+ call_one_of(:on_detask, :on_cancel, :detask, :cancel)
153
+ end
154
+
155
+ protected
156
+
157
+ def call_one_of(*ms)
158
+
159
+ m = ms.flatten.find { |mm| respond_to?(mm) }
160
+
161
+ send(m) if m
162
+ end
163
+
164
+ def reply(message=@message, force=false)
165
+
166
+ fail ArgumentError.new(
167
+ "argument to reply must be a Hash but is #{message.class}"
168
+ ) unless message.is_a?(Hash)
169
+
170
+ pt = @message['point']
171
+
172
+ ms = [ "post_#{pt}" ]; ms << :post_cancel if pt == 'detask'
173
+ #
174
+ call_one_of(ms)
175
+
176
+ msg = derive_message(message)
177
+
178
+ @ganger.return(msg) if force || @ganger
179
+
180
+ [] # very important, return no further messages
181
+ end
182
+ end
114
183
  end
115
184
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -22,7 +23,7 @@ module Flor
22
23
  @executor = nil
23
24
  end
24
25
 
25
- ROW_PSEUDO_POINTS = %w[ status tag tasker var variable ]
26
+ ROW_PSEUDO_POINTS = %w[ status tag tasker var variable ].freeze
26
27
  # "tasker", not "task", since "task" is already a message point
27
28
 
28
29
  def row_waiter?
@@ -52,7 +53,7 @@ module Flor
52
53
 
53
54
  @mutex.synchronize do
54
55
 
55
- return false unless match?(message)
56
+ return false unless msg_match?(message)
56
57
 
57
58
  @serie.shift
58
59
  return false if @serie.any?
@@ -150,7 +151,7 @@ module Flor
150
151
 
151
152
  protected
152
153
 
153
- def match?(message)
154
+ def msg_match?(message)
154
155
 
155
156
  mpoint = message['point']
156
157
 
@@ -209,7 +210,7 @@ module Flor
209
210
  (name == nil || ptr.name == name) &&
210
211
  (value == nil || ptr.value == value.to_s) }
211
212
  end
212
- alias row_match_variable? row_match_var?
213
+ alias row_match_variable? row_match_var?
213
214
 
214
215
  def row_match_tasker?(unit, rs, nid, (name, value))
215
216
 
@@ -246,15 +247,7 @@ module Flor
246
247
  end
247
248
  end
248
249
 
249
- WAIT_REX =
250
- %r{
251
- \A
252
- ([0-9_\-]+)?[ ]*
253
- (
254
- [a-z]+(?::[^:|;,\s]+){0,2}
255
- (?:[|, ][a-z]+(:[^:|;,\s]+){0,2})*
256
- )\z
257
- }x
250
+ PT_REX = /[a-z]+(?::[^:|,\s]+){0,2}/.freeze
258
251
 
259
252
  def parse_serie(s)
260
253
 
@@ -262,11 +255,23 @@ module Flor
262
255
 
263
256
  (s.is_a?(String) ? s.split(';') : s)
264
257
  .collect { |ss|
265
- m = ss.strip.match(WAIT_REX)
258
+
259
+ k = StringScanner.new(ss.strip)
260
+
261
+ ni = k.scan(Flor::START_NID_REX)
262
+
263
+ k.scan(/\s*/)
264
+
265
+ pts = []; loop do
266
+ pt = k.scan(PT_REX); break unless pt
267
+ pts << pt
268
+ k.scan(/\s*[|,]\s*/)
269
+ end
270
+
266
271
  fail ArgumentError.new(
267
- "cannot parse #{ss.strip.inspect} wait directive") unless m
268
- ni, pt = m[1, 2]
269
- [ ni, pt.split(/[|,]/).collect(&:strip) ] }
272
+ "cannot parse #{ss.strip.inspect} wait directive") unless k.eos?
273
+
274
+ [ ni, pts ] }
270
275
  end
271
276
  end
272
277
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Flor
3
4
 
@@ -11,6 +12,15 @@ module Flor
11
12
  # `wtl_row_frequency`:
12
13
  # sleep time between row waiter checks, defaults to 1
13
14
 
15
+ # Regular waiters are message waiters, they wait for a message
16
+ # that matches a pattern
17
+ #
18
+ # Row waiters are waiting for the pattern to realize in the database
19
+ # a better name would probably have been "query waiter".
20
+ # Row waiters need their own thread for checking at interval.
21
+ # Row waiters can live in a different Ruby process from the Ruby process
22
+ # performing the executions.
23
+
14
24
  DEFAULT_TIMEOUT = Flor.env_i('FLOR_DEFAULT_TIMEOUT')
15
25
 
16
26
  def initialize(unit)
@@ -42,18 +52,19 @@ module Flor
42
52
 
43
53
  def notify(executor, message)
44
54
 
45
- @mutex.synchronize do
55
+ return [] unless message['consumed']
56
+ return [] if @msg_waiters.empty?
46
57
 
47
- to_remove = []
58
+ @mutex.synchronize do
48
59
 
49
- @msg_waiters.each do |w|
50
- remove = w.notify(executor, message)
51
- to_remove << w if remove
52
- end
60
+ to_remove =
61
+ @msg_waiters.each_with_object([]) do |w, a|
62
+ remove = w.notify(executor, message)
63
+ a << w if remove
64
+ end
53
65
 
54
66
  @msg_waiters -= to_remove
55
-
56
- end if message['consumed']
67
+ end
57
68
 
58
69
  [] # no new messages
59
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-05 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: munemo
@@ -225,6 +225,7 @@ files:
225
225
  - lib/flor/pcore/twig.rb
226
226
  - lib/flor/pcore/type_of.rb
227
227
  - lib/flor/pcore/until.rb
228
+ - lib/flor/punit/abort.rb
228
229
  - lib/flor/punit/c_collect.rb
229
230
  - lib/flor/punit/c_each.rb
230
231
  - lib/flor/punit/c_for_each.rb
@@ -236,7 +237,7 @@ files:
236
237
  - lib/flor/punit/do_trap.rb
237
238
  - lib/flor/punit/every.rb
238
239
  - lib/flor/punit/graft.rb
239
- - lib/flor/punit/m_ram.rb
240
+ - lib/flor/punit/m_receive_and_merge.rb
240
241
  - lib/flor/punit/on_timeout.rb
241
242
  - lib/flor/punit/part.rb
242
243
  - lib/flor/punit/schedule.rb
@@ -247,12 +248,17 @@ files:
247
248
  - lib/flor/punit/trap.rb
248
249
  - lib/flor/to_string.rb
249
250
  - lib/flor/tools/env.rb
251
+ - lib/flor/tools/firb.rb
250
252
  - lib/flor/tools/shell.rb
251
253
  - lib/flor/tools/shell_out.rb
254
+ - lib/flor/tt.rb
252
255
  - lib/flor/unit.rb
253
256
  - lib/flor/unit/caller.rb
257
+ - lib/flor/unit/caller_jruby.rb
258
+ - lib/flor/unit/dump.rb
254
259
  - lib/flor/unit/executor.rb
255
260
  - lib/flor/unit/ganger.rb
261
+ - lib/flor/unit/gangers.rb
256
262
  - lib/flor/unit/hloader.rb
257
263
  - lib/flor/unit/hook.rb
258
264
  - lib/flor/unit/hooker.rb
@@ -272,16 +278,16 @@ files:
272
278
  - lib/flor/unit/taskers.rb
273
279
  - lib/flor/unit/waiter.rb
274
280
  - lib/flor/unit/wlist.rb
275
- homepage: http://github.com/floraison
281
+ homepage: https://github.com/floraison
276
282
  licenses:
277
283
  - MIT
278
284
  metadata:
279
- changelog_uri: http://github.com/floraison/flor/blob/master/CHANGELOG.md
280
- documentation_uri: http://github.com/floraison/flor/tree/master/doc
281
- bug_tracker_uri: http://github.com/floraison/flor/issues
285
+ changelog_uri: https://github.com/floraison/flor/blob/master/CHANGELOG.md
286
+ documentation_uri: https://github.com/floraison/flor/tree/master/doc
287
+ bug_tracker_uri: https://github.com/floraison/flor/issues
282
288
  mailing_list_uri: https://groups.google.com/forum/#!forum/floraison
283
- homepage_uri: http://github.com/floraison/flor
284
- source_code_uri: http://github.com/floraison/flor
289
+ homepage_uri: https://github.com/floraison/flor
290
+ source_code_uri: https://github.com/floraison/flor
285
291
  post_install_message:
286
292
  rdoc_options: []
287
293
  require_paths:
@@ -297,8 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
297
303
  - !ruby/object:Gem::Version
298
304
  version: '0'
299
305
  requirements: []
300
- rubyforge_project:
301
- rubygems_version: 2.6.14.1
306
+ rubygems_version: 3.0.3
302
307
  signing_key:
303
308
  specification_version: 4
304
309
  summary: A Ruby workflow engine