flor 1.0.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,29 @@ module Flor
29
29
  alias task_name taskname
30
30
 
31
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
32
55
 
33
56
  def execution
34
57
 
@@ -112,5 +135,50 @@ module Flor
112
135
  h
113
136
  end
114
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
115
183
  end
116
184
 
@@ -23,7 +23,7 @@ module Flor
23
23
  @executor = nil
24
24
  end
25
25
 
26
- ROW_PSEUDO_POINTS = %w[ status tag tasker var variable ]
26
+ ROW_PSEUDO_POINTS = %w[ status tag tasker var variable ].freeze
27
27
  # "tasker", not "task", since "task" is already a message point
28
28
 
29
29
  def row_waiter?
@@ -53,7 +53,7 @@ module Flor
53
53
 
54
54
  @mutex.synchronize do
55
55
 
56
- return false unless match?(message)
56
+ return false unless msg_match?(message)
57
57
 
58
58
  @serie.shift
59
59
  return false if @serie.any?
@@ -151,7 +151,7 @@ module Flor
151
151
 
152
152
  protected
153
153
 
154
- def match?(message)
154
+ def msg_match?(message)
155
155
 
156
156
  mpoint = message['point']
157
157
 
@@ -247,15 +247,7 @@ module Flor
247
247
  end
248
248
  end
249
249
 
250
- WAIT_REX =
251
- %r{
252
- \A
253
- ([0-9_\-]+)?[ ]*
254
- (
255
- [a-z]+(?::[^:|;,\s]+){0,2}
256
- (?:[|, ][a-z]+(:[^:|;,\s]+){0,2})*
257
- )\z
258
- }x
250
+ PT_REX = /[a-z]+(?::[^:|,\s]+){0,2}/.freeze
259
251
 
260
252
  def parse_serie(s)
261
253
 
@@ -263,11 +255,23 @@ module Flor
263
255
 
264
256
  (s.is_a?(String) ? s.split(';') : s)
265
257
  .collect { |ss|
266
- 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
+
267
271
  fail ArgumentError.new(
268
- "cannot parse #{ss.strip.inspect} wait directive") unless m
269
- ni, pt = m[1, 2]
270
- [ ni, pt.split(/[|,]/).collect(&:strip) ] }
272
+ "cannot parse #{ss.strip.inspect} wait directive") unless k.eos?
273
+
274
+ [ ni, pts ] }
271
275
  end
272
276
  end
273
277
  end
@@ -12,6 +12,15 @@ module Flor
12
12
  # `wtl_row_frequency`:
13
13
  # sleep time between row waiter checks, defaults to 1
14
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
+
15
24
  DEFAULT_TIMEOUT = Flor.env_i('FLOR_DEFAULT_TIMEOUT')
16
25
 
17
26
  def initialize(unit)
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: 1.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-22 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: munemo
@@ -237,7 +237,7 @@ files:
237
237
  - lib/flor/punit/do_trap.rb
238
238
  - lib/flor/punit/every.rb
239
239
  - lib/flor/punit/graft.rb
240
- - lib/flor/punit/m_ram.rb
240
+ - lib/flor/punit/m_receive_and_merge.rb
241
241
  - lib/flor/punit/on_timeout.rb
242
242
  - lib/flor/punit/part.rb
243
243
  - lib/flor/punit/schedule.rb
@@ -248,6 +248,7 @@ files:
248
248
  - lib/flor/punit/trap.rb
249
249
  - lib/flor/to_string.rb
250
250
  - lib/flor/tools/env.rb
251
+ - lib/flor/tools/firb.rb
251
252
  - lib/flor/tools/shell.rb
252
253
  - lib/flor/tools/shell_out.rb
253
254
  - lib/flor/tt.rb
@@ -257,6 +258,7 @@ files:
257
258
  - lib/flor/unit/dump.rb
258
259
  - lib/flor/unit/executor.rb
259
260
  - lib/flor/unit/ganger.rb
261
+ - lib/flor/unit/gangers.rb
260
262
  - lib/flor/unit/hloader.rb
261
263
  - lib/flor/unit/hook.rb
262
264
  - lib/flor/unit/hooker.rb