easy_flow 0.54.0 → 0.56.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ac513b344a1d8840cfe5fee24ae751eda1e9f2e24a6b4d1fcd7199091a621d9
4
- data.tar.gz: 9cf5f9b0edff6739beda59b1e5aa23064121ab6211344dcc1792eb407dd67f62
3
+ metadata.gz: 1c39928a05f4b9308506700c4d3c71a27c93967c41bf00b67f15bf420493c6c9
4
+ data.tar.gz: 6c424c40e48c87ce7be0b54aa94f71300ca107286adca1a1ee5da5958f16284b
5
5
  SHA512:
6
- metadata.gz: 58ca418648f6f5d8bd2febb3ea4204aa8e296928094c147cba63dd2319ccb772ba8373950410ad0235157902311194147b8c1ebebaf00d51d26045106a43016a
7
- data.tar.gz: 797dec1241a9d2a38d395c75cc4bd4754045d7ad13040981bd7758c738db620ecc7853c200098761532b0d179179785fc533e747f4929808a48f972dcb912327
6
+ metadata.gz: 50b72ed9aeac7af50ac05d604ccb2ac7d28f0b47750e2d578917a89ae40307499b675b974518ecb0917c9e28a6b07da49a1acec3eb1208c2ad45733bcce7cf0f
7
+ data.tar.gz: 3a123bf087390067977a4801cb8e99e18cd6dbcc986a33f5579d549d17f4bc6c99b96de42e747582c143d3141c1d232ca85e06bedc72684df7eff18f0cf220cd
data/README.md CHANGED
@@ -3,20 +3,55 @@ Guided, versioned, branching flows for Rails apps
3
3
 
4
4
  ## For each
5
5
 
6
- A For each step (`:for_each`) is drawn on the canvas as a dashed box. It runs the steps inside the box once for each item of a list an earlier step recorded, one item after another, in list order. It runs only in a flow that saves its runs, and a flow that keeps nothing tells the visitor so.
6
+ A For each step (`:for_each`) is drawn on the canvas as a dashed box. It runs the steps inside the box once for each item of a list an earlier step recorded, starting items in list order. It runs only in a flow that saves its runs, and a flow that keeps nothing tells the visitor so.
7
7
 
8
8
  Its settings:
9
9
 
10
10
  - `list` names the list as `<step>.<output>`, such as `outline.variants`, or as the step id alone when that step recorded the array as its whole value.
11
- - `concurrency` is how many items may run at the same time. Items still run one at a time.
12
- - `on_item_failure` is `continue` or `stop`. A failed item still lets the next item start.
11
+ - `concurrency` is how many items may be unfinished at the same time. With none set, items run one at a time.
12
+ - `on_item_failure` is `continue` or `stop`. Under `continue`, a failed item ends only that item. Under `stop`, no item starts after an item has failed, and the items already running are allowed to end.
13
+ - `item_limit` is the most items the list may hold. With none set, the limit is 100.
13
14
 
14
- Each visit of a held step is recorded under its item number, counting from 1, such as `write@item2`, and a further visit inside the same item adds the visit number, such as `write@item2@2`. A held step's input can tick `The current item` to receive that item's value from the list. An input naming another held step receives that step's output for the same item. An item ends when its steps leave the box, or when a held step routes to `failed`.
15
+ Each visit of a held step is recorded under its item number, counting from 1, such as `write@item2`, and a further visit inside the same item adds the visit number, such as `write@item2@2`. A held step's input can tick `The current item` to receive that item's value from the list. An input naming another held step receives that step's output for the same item. An item ends when its steps leave the box, or when a held step routes to `failed`. An item counts as running once one of its held steps has a recorded visit.
16
+
17
+ ### Steps ready now
18
+
19
+ `run.next_step(run.recorded)` names one step, as it always has. `run.ready_steps` names every step that may run now. Outside a For each step it holds the next step alone. Inside one it holds the next held step of each unfinished item, never more than `concurrency` of them, in list order.
20
+
21
+ ```ruby
22
+ run.ready_steps.map(&:id)
23
+ # => ["write@item1", "write@item2", "write@item3"]
24
+ run.record("write@item2", { "result" => "passed" })
25
+ run.advance
26
+ run.ready_steps.map(&:id)
27
+ # => ["write@item1", "write@item3", "write@item4"]
28
+ ```
29
+
30
+ `run.advance` runs every acting step among the ready steps, not only the first.
31
+
32
+ ### What it records
15
33
 
16
34
  Once every item has ended, the For each step records these outputs under its own id:
17
35
 
18
36
  - `result` is `passed` when no item failed, and `failed` otherwise.
19
- - `items` holds one entry per item, mapping each held step the item reached to its latest value.
37
+ - `items` holds one entry per item that ran, mapping each held step the item reached to its latest value.
20
38
  - `passed` and `failed` count the items.
39
+ - `reason` says why the step failed when its list could not be run.
21
40
 
22
41
  A step after the box reads them through an input that names the For each step and one of those outputs. An empty list runs no items, records `items` as an empty list, and the run goes on to the step after the box.
42
+
43
+ The run leaves the box on the connection that leaves it from a held step. Under `stop`, once an item has failed and the running items have ended, the run leaves on the `failed` connection of the held step that failed.
44
+
45
+ ### A list that cannot be run
46
+
47
+ The step starts no item and records `result` as `failed` with a `reason` when:
48
+
49
+ - the earlier step recorded no value under the named output, such as `The step outline recorded no value under variants.`
50
+ - the value is not a list, such as `The list outline.variants is text, not a list.`, naming text, a number or a hash.
51
+ - the list holds more items than `item_limit`, such as `The list outline.variants holds 120 items, more than the limit of 100.`
52
+
53
+ The run then leaves on a `failed` connection that leaves the box from a held step. With none, the run stops there, as it does after any failed step with no `failed` connection.
54
+
55
+ ### Reaching it again
56
+
57
+ A run that comes back to a For each step, through a later step that loops back to it or to a step before it, runs the held steps again for each item of the list as it stands then. The second pass records its visits with a pass number after the item, such as `write@item2@pass2` and `write@item2@pass2@2`, and the third pass with `pass3`. The first pass's keys carry no pass number. The For each step records each pass's outputs under its own visit, `variants` for the first and `variants@2` for the second, so both stay readable, and a step after the box reads the latest pass. A held step's input naming another held step reads that step's output for the same item in the same pass.
@@ -1,6 +1,8 @@
1
1
  module EasyFlow
2
2
  class Digest
3
3
  Path = Struct.new(:recorded, :latest, :latest_times)
4
+ ItemWalk = Struct.new(:held, :failed_at, :started)
5
+ ItemsWalk = Struct.new(:ready, :stopped_at, :problem)
4
6
 
5
7
  def initialize(document, registry: EasyFlow.registry)
6
8
  @document = document
@@ -82,7 +84,11 @@ module EasyFlow
82
84
 
83
85
  def items_ended(id, state)
84
86
  box = step(id)
85
- ended = items_of(box, latest_values(state)).each_index.map { |index| item_values(box, index + 1, state) }
87
+ problem = list_problem(box, latest_values(state))
88
+ return { "result" => "failed", "reason" => problem, "items" => [], "passed" => 0, "failed" => 0 } if problem
89
+
90
+ pass = VisitKey.parse(id).visit
91
+ ended = items_of(box, latest_values(state)).each_index.map { |index| item_values(box, index + 1, pass, state) }.reject(&:empty?)
86
92
  failed = ended.count { |values| values.any? { |held, value| failed?(step(held), state.merge(held => value), {}) } }
87
93
 
88
94
  { "result" => failed.zero? ? "passed" : "failed", "items" => ended, "passed" => ended.size - failed, "failed" => failed }
@@ -100,6 +106,10 @@ module EasyFlow
100
106
  walk(state, times)[1]
101
107
  end
102
108
 
109
+ def ready_steps(state, times = {})
110
+ walk(state, times)[3].to_a
111
+ end
112
+
103
113
  def output(state, times = {})
104
114
  ended_setting(state, times, "output")
105
115
  end
@@ -160,9 +170,9 @@ module EasyFlow
160
170
  visits[cursor.id] += 1
161
171
  answers_at_visit[cursor.id] = answered
162
172
  key = visit_key(cursor.id, visits[cursor.id])
163
- held = repeats?(cursor) && walk_items(cursor, state, times, Path.new(recorded, latest, latest_times))
164
- return [ recorded, held ] if held
165
- return [ recorded, cursor.with(id: key) ] if pending?(cursor, key, state)
173
+ items = repeats?(cursor) ? walk_items(cursor, visits[cursor.id], state, times, Path.new(recorded, latest, latest_times)) : ItemsWalk.new([], nil, nil)
174
+ return [ recorded, items.ready.first, nil, items.ready ] if items.ready.any? && !state.key?(key)
175
+ return [ recorded, cursor.with(id: key), nil, [ cursor.with(id: key) ] ] if pending?(cursor, key, state)
166
176
 
167
177
  if state.key?(key)
168
178
  recorded << key
@@ -170,18 +180,26 @@ module EasyFlow
170
180
  latest_times[cursor.id] = times[key] if times.key?(key)
171
181
  answered += 1 if step_type(cursor)&.awaits_input?
172
182
  end
173
- cursor = repeats?(cursor) ? box_exit(cursor) : successor(cursor, reached(state, recorded).merge(latest), latest_times)
183
+ cursor = repeats?(cursor) ? box_exit(cursor, items) : successor(cursor, reached(state, recorded).merge(latest), latest_times)
174
184
  end
175
185
 
176
186
  [ recorded, nil ]
177
187
  end
178
188
 
179
- def walk_items(box, state, times, path)
180
- items_of(box, path.latest).each_index do |index|
181
- held = walk_item(box, index + 1, state, times, path)
182
- return held if held
183
- end
184
- nil
189
+ def walk_items(box, pass, state, times, path)
190
+ walked = items_of(box, path.latest).each_index.map { |index| walk_item(box, VisitKey.new(step: box.id, item: index + 1, pass: pass), state, times, path) }
191
+ stopped_at = walked.find(&:failed_at)&.failed_at if stops_on_failure?(box)
192
+ ready = walked.select(&:held).select { |item| item.started || !stopped_at }.first(concurrency_of(box)).map(&:held)
193
+
194
+ ItemsWalk.new(ready, stopped_at, list_problem(box, path.latest))
195
+ end
196
+
197
+ def stops_on_failure?(box)
198
+ box.config["on_item_failure"].to_s == "stop"
199
+ end
200
+
201
+ def concurrency_of(box)
202
+ [ box.config["concurrency"].to_i, 1 ].max
185
203
  end
186
204
 
187
205
  def walk_item(box, item, state, times, path)
@@ -189,24 +207,28 @@ module EasyFlow
189
207
  recorded_at_visit = {}
190
208
  cursor = first_held(box)
191
209
 
210
+ started = false
211
+
192
212
  while cursor && held_by?(box, cursor)
193
- return if visits[cursor.id].positive? && recorded_at_visit[cursor.id] == path.recorded.size
213
+ return ItemWalk.new(nil, nil, started) if visits[cursor.id].positive? && recorded_at_visit[cursor.id] == path.recorded.size
194
214
 
195
215
  visits[cursor.id] += 1
196
216
  recorded_at_visit[cursor.id] = path.recorded.size
197
- key = item_key(cursor.id, item, visits[cursor.id])
198
- return cursor.with(id: key) if pending?(cursor, key, state)
217
+ key = item.with(step: cursor.id, visit: visits[cursor.id]).to_s
218
+ return ItemWalk.new(cursor.with(id: key), nil, started) if pending?(cursor, key, state)
199
219
 
200
220
  if state.key?(key)
221
+ started = true
201
222
  path.recorded << key
202
223
  path.latest[cursor.id] = state[key]
203
224
  path.latest_times[cursor.id] = times[key] if times.key?(key)
204
225
  end
205
226
  routed = reached(state, path.recorded).merge(path.latest)
206
- return if failed?(cursor, routed, path.latest_times)
227
+ return ItemWalk.new(nil, cursor, started) if failed?(cursor, routed, path.latest_times)
207
228
 
208
229
  cursor = successor(cursor, routed, path.latest_times)
209
230
  end
231
+ ItemWalk.new(nil, nil, started)
210
232
  end
211
233
 
212
234
  def failed?(node, state, times)
@@ -214,14 +236,37 @@ module EasyFlow
214
236
  end
215
237
 
216
238
  def items_of(box, latest)
239
+ list_problem(box, latest) ? [] : listed_value(box, latest)
240
+ end
241
+
242
+ def listed_value(box, latest)
217
243
  step_id, output = step_type(box).list_named_by(box).split(".", 2)
218
244
  listed = latest[step_id]
219
- listed = listed[output] if listed.is_a?(Hash) && output
220
- listed.is_a?(Array) ? listed : []
245
+ listed.is_a?(Hash) && output ? listed[output] : listed
246
+ end
247
+
248
+ def list_problem(box, latest)
249
+ named = step_type(box).list_named_by(box)
250
+ step_id, output = named.split(".", 2)
251
+ listed = listed_value(box, latest)
252
+ return "The step #{step_id} recorded no value#{" under #{output}" if output}." if listed.nil?
253
+
254
+ return "The list #{named} is #{kind_of_value(listed)}, not a list." unless listed.is_a?(Array)
255
+
256
+ "The list #{named} holds #{listed.size} items, more than the limit of #{item_limit_of(box)}." if listed.size > item_limit_of(box)
221
257
  end
222
258
 
223
- def item_key(id, item, visit)
224
- VisitKey.new(step: id, item: item, visit: visit).to_s
259
+ def item_limit_of(box)
260
+ box.config["item_limit"].presence&.to_i || ForEach::ITEM_LIMIT
261
+ end
262
+
263
+ def kind_of_value(value)
264
+ case value
265
+ when String then "text"
266
+ when Numeric then "a number"
267
+ when Hash then "a hash"
268
+ else "true or false"
269
+ end
225
270
  end
226
271
 
227
272
  def latest_values(state)
@@ -229,8 +274,8 @@ module EasyFlow
229
274
  .transform_values { |visits| state[visits.max_by(&:visit).to_s] }
230
275
  end
231
276
 
232
- def item_values(box, item, state)
233
- visits = state.keys.map { |key| VisitKey.parse(key) }.select { |visit| visit.item == item }
277
+ def item_values(box, item, pass, state)
278
+ visits = state.keys.map { |key| VisitKey.parse(key) }.select { |visit| visit.item == item && visit.pass == pass }
234
279
  Array(box.config["holds"]).filter_map do |held|
235
280
  latest = visits.select { |visit| visit.step == held }.max_by(&:visit)
236
281
  [ held, state[latest.to_s] ] if latest
@@ -246,9 +291,13 @@ module EasyFlow
246
291
  entering && @document.node(entering.to)
247
292
  end
248
293
 
249
- def box_exit(box)
294
+ def box_exit(box, items)
250
295
  held = Array(box.config["holds"])
251
- leaving = @document.edges.find { |edge| held.include?(edge.from) && !held.include?(edge.to) && edge.on.to_s != "failed" }
296
+ leaving = @document.edges.select { |edge| held.include?(edge.from) && !held.include?(edge.to) }.find do |edge|
297
+ next edge.from == items.stopped_at.id && edge.on.to_s == "failed" if items.stopped_at
298
+
299
+ items.problem ? edge.on.to_s == "failed" : edge.on.to_s != "failed"
300
+ end
252
301
  leaving && @document.node(leaving.to)
253
302
  end
254
303
 
@@ -2,6 +2,8 @@ module EasyFlow
2
2
  class ForEach
3
3
  include Step
4
4
 
5
+ ITEM_LIMIT = 100
6
+
5
7
  step_name "For each"
6
8
 
7
9
  holds_steps
@@ -11,6 +13,7 @@ module EasyFlow
11
13
  setting :list, type: :string
12
14
  setting :concurrency, type: :integer
13
15
  setting :on_item_failure, type: :select, options: %w[continue stop]
16
+ setting :item_limit, type: :integer, label: "Most items"
14
17
 
15
18
  output :result, values: %w[passed failed]
16
19
  output :items
@@ -26,16 +26,16 @@ module EasyFlow
26
26
  private_class_method :value_of
27
27
 
28
28
  def self.latest_output(node, input, state, run)
29
- latest_visit = latest_visit_of(input["step"], VisitKey.parse(node.id).item, state)
29
+ latest_visit = latest_visit_of(input["step"], VisitKey.parse(node.id), state)
30
30
  return if unreported?(input, state[latest_visit], run)
31
31
 
32
32
  CompletedAt.value_of(state, {}, latest_visit, input["output"])
33
33
  end
34
34
  private_class_method :latest_output
35
35
 
36
- def self.latest_visit_of(step, item, state)
36
+ def self.latest_visit_of(step, reader, state)
37
37
  visits = state.keys.to_h { |key| [ key, VisitKey.parse(key) ] }.select { |_key, visit| visit.step == step }
38
- same_item = visits.select { |_key, visit| visit.item == item }
38
+ same_item = visits.select { |_key, visit| visit.item == reader.item && visit.pass == reader.pass }
39
39
  (same_item.presence || visits.reject { |_key, visit| visit.item }).max_by { |_key, visit| visit.visit }&.first
40
40
  end
41
41
  private_class_method :latest_visit_of
@@ -40,6 +40,10 @@ module EasyFlow
40
40
  digest.next_step(state.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
41
41
  end
42
42
 
43
+ def ready_steps(state = recorded)
44
+ digest.ready_steps(state.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
45
+ end
46
+
43
47
  def ended_at_end?
44
48
  digest.ended_at_end?(recorded.transform_keys(&:to_s), completed_at.transform_keys(&:to_s))
45
49
  end
@@ -57,8 +61,9 @@ module EasyFlow
57
61
  end
58
62
 
59
63
  def held_until
60
- stopped_at = next_step(recorded)
61
- Wait.held_until(digest.step(stopped_at.id), CompletedAt.latest(completed_at)) if stopped_at&.type == "wait"
64
+ stopped_at = next_step(recorded) or return
65
+ node = digest.step(stopped_at.id)
66
+ EasyFlow.registry.fetch(stopped_at.type).held_until(node, recorded.transform_keys(&:to_s), CompletedAt.latest(completed_at))
62
67
  end
63
68
 
64
69
  def waiting_on
@@ -29,11 +29,18 @@ module EasyFlow
29
29
  end
30
30
 
31
31
  def run(progress)
32
- while (node = @digest.next_step(named(progress.recorded), named(progress.completed_at))) && goes_on?(node, named(progress.recorded), CompletedAt.latest(named(progress.completed_at))) && (progress.saved? || refusal_of(node).nil?)
33
- progress.record(node.id, result_of(@digest.step(node.id), named(progress.recorded), progress.run))
32
+ while (node = going_on(progress))
33
+ progress.record(node.id, result_of(node, named(progress.recorded), progress.run))
34
34
  end
35
- progress.start_inner(node) if node && starts_a_flow?(node)
36
- progress.ended unless node
35
+ waiting = @digest.next_step(named(progress.recorded), named(progress.completed_at))
36
+ progress.start_inner(waiting) if waiting && starts_a_flow?(waiting)
37
+ progress.ended unless waiting
38
+ tell_held(progress.run)
39
+ end
40
+
41
+ def tell_held(run)
42
+ held = run&.held_until
43
+ EasyFlow.on_held&.call(run, held) if held
37
44
  end
38
45
 
39
46
  def unsaved_refusal(state, times: {})
@@ -63,6 +70,13 @@ module EasyFlow
63
70
 
64
71
  private
65
72
 
73
+ def going_on(progress)
74
+ state = named(progress.recorded)
75
+ @digest.ready_steps(state, named(progress.completed_at)).find do |node|
76
+ goes_on?(node, state, CompletedAt.latest(named(progress.completed_at))) && (progress.saved? || refusal_of(node).nil?)
77
+ end
78
+ end
79
+
66
80
  def refusal_of(node)
67
81
  own_refusal(node) || own_refusal(node && @digest.holder_of(node.id))
68
82
  end
@@ -103,9 +117,10 @@ module EasyFlow
103
117
  @registry.registered?(node.type) && @registry.fetch(node.type).waits? && @registry.fetch(node.type).ready?(node, state, times)
104
118
  end
105
119
 
106
- def result_of(node, state, run)
120
+ def result_of(visited, state, run)
121
+ node = @digest.step(visited.id)
107
122
  return allowed(node, state).first.to_s if decided?(node, state)
108
- return @digest.items_ended(node.id, state) if @digest.repeats?(node)
123
+ return @digest.items_ended(visited.id, state) if @digest.repeats?(node)
109
124
 
110
125
  acts?(node) ? @registry.fetch(node.type).process(node, state, run: run) : true
111
126
  end
@@ -75,6 +75,10 @@ module EasyFlow
75
75
  @readiness = readiness
76
76
  end
77
77
 
78
+ def holds_until(&hold)
79
+ @hold = hold
80
+ end
81
+
78
82
  def step_name(value)
79
83
  @step_name = value
80
84
  end
@@ -185,7 +189,7 @@ module EasyFlow
185
189
  StepType.new(id: @id, step_name: @step_name, settings: settings, awaits_input: @awaits_input,
186
190
  ends_here: @ends_here, begins_here: @begins_here, starts_a_flow: @starts_a_flow, plays_the_picked_flow: @plays_the_picked_flow, holds_steps: @holds_steps, repeats_held_steps_for: @repeats_held_steps_for, flow_chooser: @flow_chooser, run_chooser: @run_chooser, behaviour: @behaviour, routing: @routing,
187
191
  display: @display, drawn_by: @drawn_by, naming_field: @naming_field, naming: @naming, summarizing: @summarizing, details: @details, linking: @linking,
188
- outputs: @declared_outputs, outputs_named_by: @outputs_named_by, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness, return_rule: @return_rule, unsaved_refusal: @unsaved_refusal)
192
+ outputs: @declared_outputs, outputs_named_by: @outputs_named_by, answer_check: @answer_check, answer_labelling: @answer_labelling, readiness: @readiness, hold: @hold, return_rule: @return_rule, unsaved_refusal: @unsaved_refusal)
189
193
  end
190
194
 
191
195
  def settings
@@ -12,7 +12,7 @@ module EasyFlow
12
12
 
13
13
  def initialize(id:, step_name:, settings:, awaits_input:, behaviour:, routing:,
14
14
  ends_here: false, begins_here: false, starts_a_flow: false, plays_the_picked_flow: false, holds_steps: false, repeats_held_steps_for: nil, flow_chooser: nil, run_chooser: nil, display: nil, drawn_by: nil,
15
- naming_field: nil, naming: nil, summarizing: nil, details: [], linking: nil, outputs: [], outputs_named_by: nil, answer_check: nil, answer_labelling: nil, readiness: nil, return_rule: nil, unsaved_refusal: nil)
15
+ naming_field: nil, naming: nil, summarizing: nil, details: [], linking: nil, outputs: [], outputs_named_by: nil, answer_check: nil, answer_labelling: nil, readiness: nil, hold: nil, return_rule: nil, unsaved_refusal: nil)
16
16
  @id = id
17
17
  @step_name = step_name
18
18
  @settings = settings
@@ -39,6 +39,7 @@ module EasyFlow
39
39
  @answer_check = answer_check
40
40
  @answer_labelling = answer_labelling
41
41
  @readiness = readiness
42
+ @hold = hold
42
43
  @return_rule = return_rule
43
44
  @unsaved_refusal = unsaved_refusal
44
45
  end
@@ -75,6 +76,10 @@ module EasyFlow
75
76
  @readiness.call(node, state, times)
76
77
  end
77
78
 
79
+ def held_until(node, state, times = {})
80
+ @hold&.call(node, state, times)
81
+ end
82
+
78
83
  def comes_back?(node, state)
79
84
  @return_rule&.call(node, state) || false
80
85
  end
@@ -1,13 +1,18 @@
1
1
  module EasyFlow
2
- VisitKey = Data.define(:step, :item, :visit) do
2
+ VisitKey = Data.define(:step, :item, :visit, :pass) do
3
3
  def self.parse(key)
4
4
  step, *rest = key.to_s.split("@")
5
5
  item = rest.shift.delete_prefix("item").to_i if rest.first.to_s.start_with?("item")
6
- new(step: step, item: item, visit: (rest.first || 1).to_i)
6
+ pass = rest.shift.delete_prefix("pass").to_i if rest.first.to_s.start_with?("pass")
7
+ new(step: step, item: item, visit: (rest.first || 1).to_i, pass: pass || 1)
8
+ end
9
+
10
+ def initialize(step:, item: nil, visit: 1, pass: 1)
11
+ super
7
12
  end
8
13
 
9
14
  def to_s
10
- [ step, ("item#{item}" if item), (visit if visit > 1) ].compact.join("@")
15
+ [ step, ("item#{item}" if item), ("pass#{pass}" if pass > 1), (visit if visit > 1) ].compact.join("@")
11
16
  end
12
17
  end
13
18
  end
@@ -13,6 +13,7 @@ module EasyFlow
13
13
  summarizes_by { |node| Wait.summarized(node.config) }
14
14
 
15
15
  waits_until { |node, _state, times| Wait.held_until(node, times)&.then { |held| held <= Time.current } || false }
16
+ holds_until { |node, _state, times| Wait.held_until(node, times) }
16
17
 
17
18
  def self.named(config)
18
19
  return config["date"] if config["date"].present?
@@ -1,3 +1,3 @@
1
1
  module EasyFlow
2
- VERSION = "0.54.0"
2
+ VERSION = "0.56.0"
3
3
  end
data/lib/easy_flow.rb CHANGED
@@ -30,7 +30,7 @@ module EasyFlow
30
30
 
31
31
  class << self
32
32
  attr_writer :base_controller
33
- attr_accessor :file_store, :picture_store, :data_source
33
+ attr_accessor :file_store, :picture_store, :data_source, :on_held
34
34
 
35
35
  def base_controller
36
36
  @base_controller || "ActionController::Base"
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-develop
3
- description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, takes several answers at once, computes a value from earlier answers, records several values under names an admin enters in the step's settings, counts how many times an earlier step was answered so a loop can give up after a number of tries, picks the next branch, or holds the visitor until something outside the flow has happened), adding a step type an admin draws as a box that holds other steps on the canvas, running the steps a For each box holds once per item of a list an earlier step recorded and reading each item's values and the passed and failed counts after the box, branching on whether all or any of several comparisons of earlier answers hold, holding a run until a number of minutes after an earlier answer, the next time of day after it, or a date, branching on the hour, weekday or time an earlier step was completed or on the minutes between two completed steps, reading when each step was completed and when a waiting run will move on, showing a step differently depending on the visitor's stored run, branching on what a visitor ticked on a checklist, moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, letting an admin pick another flow of the same host in a step's settings, adding a step type that starts another flow and works out which flow and version to run from its own settings, adding a step type that starts another flow chosen from the visitor's run, such as its owner or its answers, offering a visitor only the answers to a step that their earlier answers allow, filling in a step that has only one possible answer without asking it, skipping a step that does not apply to a visitor, letting an admin edit a value stored on one of the app's own records from a step's settings on the canvas, serving a host's flows from the app's own controller and routes, starting a visitor's run on a published version of a flow other than the live one, acting when a visitor finishes a flow, acting on the output a visitor's flow ended with, telling whether a run ended at an End step or was stopped by a loop that came back with nothing new answered and at which step, keeping a flow from being published while a step that starts another flow names a flow or version that cannot run or leads back to the flow it sits in, finding the run of another flow that a Flow step started, the run a waiting run is waiting on, and the run that started it, sending a visitor back to the run that started a flow once that flow ends, handling a run whose starting run was removed with its flow, handling a Flow step that cannot start its flow, whose flow ended with no output, or whose flow was stopped by a loop, taking one file or several from a visitor at a step, showing a one-line summary of a step's settings on its canvas card, showing a step's recorded answer by a label the step type works out, and reading a run's recorded answers and question labels, including every answer ticked on a checklist and every visit's answer when a flow loops back to a question already asked, and showing on the app's own page where a run stands, with each step's state, status line and link — MUST BE USED instead of hand-rolling questionnaire steps, checkbox lists, file upload steps, branching logic, answer lists filtered by earlier answers, skipped questions, number comparisons, comparisons of two earlier answers, and/or conditions over several comparisons, hard-coded setting options, copying a record's value into a flow and back, answer validation, retry counters, timers or scheduled delays, step completion timestamps, polling or "come back later" pages, flow controllers, answer lookups or hand-drawn run diagrams.
3
+ description: Use PROACTIVELY for adding a step type to easy_flow flows (a step that asks the visitor something, takes several answers at once, computes a value from earlier answers, records several values under names an admin enters in the step's settings, counts how many times an earlier step was answered so a loop can give up after a number of tries, picks the next branch, or holds the visitor until something outside the flow has happened), adding a step type an admin draws as a box that holds other steps on the canvas, running the steps a For each box holds once per item of a list an earlier step recorded and reading each item's values and the passed and failed counts after the box, branching on whether all or any of several comparisons of earlier answers hold, holding a run until a number of minutes after an earlier answer, the next time of day after it, or a date, branching on the hour, weekday or time an earlier step was completed or on the minutes between two completed steps, reading when each step was completed and when a waiting run will move on, declaring the time a waiting step type of the app's own holds a run until, showing a step differently depending on the visitor's stored run, branching on what a visitor ticked on a checklist, moving a paused run on once what it waits for has happened, refusing a blank or invalid answer to a step with a message, offering an admin a step setting whose options are read from the app's own records, letting an admin pick another flow of the same host in a step's settings, adding a step type that starts another flow and works out which flow and version to run from its own settings, adding a step type that starts another flow chosen from the visitor's run, such as its owner or its answers, offering a visitor only the answers to a step that their earlier answers allow, filling in a step that has only one possible answer without asking it, skipping a step that does not apply to a visitor, letting an admin edit a value stored on one of the app's own records from a step's settings on the canvas, serving a host's flows from the app's own controller and routes, starting a visitor's run on a published version of a flow other than the live one, acting when a visitor finishes a flow, acting on the output a visitor's flow ended with, telling whether a run ended at an End step or was stopped by a loop that came back with nothing new answered and at which step, keeping a flow from being published while a step that starts another flow names a flow or version that cannot run or leads back to the flow it sits in, finding the run of another flow that a Flow step started, the run a waiting run is waiting on, and the run that started it, sending a visitor back to the run that started a flow once that flow ends, handling a run whose starting run was removed with its flow, handling a Flow step that cannot start its flow, whose flow ended with no output, or whose flow was stopped by a loop, taking one file or several from a visitor at a step, showing a one-line summary of a step's settings on its canvas card, showing a step's recorded answer by a label the step type works out, and reading a run's recorded answers and question labels, including every answer ticked on a checklist and every visit's answer when a flow loops back to a question already asked, and showing on the app's own page where a run stands, with each step's state, status line and link — MUST BE USED instead of hand-rolling questionnaire steps, checkbox lists, file upload steps, branching logic, answer lists filtered by earlier answers, skipped questions, number comparisons, comparisons of two earlier answers, and/or conditions over several comparisons, hard-coded setting options, copying a record's value into a flow and back, answer validation, retry counters, timers or scheduled delays, step completion timestamps, polling or "come back later" pages, flow controllers, answer lookups or hand-drawn run diagrams.
4
4
  tools: Read, Write, Edit, Grep
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -17,6 +17,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
17
17
  - `EasyFlow.step` — declares and registers a step type in one call from a block of the same words, for a type small enough not to need its own class.
18
18
  - `labels_answer_by` — a word in a step type's declaration giving the label a run's recorded answer to a step of that type is shown by, on the completion page and from `EasyFlow::QuestionRunner#choice_label`.
19
19
  - `outputs_named_by` — a word in a step type's declaration adding one output for each entry an admin enters in one of the type's list settings, named by that entry, so the admin decides the names of the values the step records.
20
+ - `holds_until` — a word in a step type's declaration giving the time a run stopped at a step of that type is held until, read back with `EasyFlow::Run#held_until`.
20
21
  - `EasyFlow::Inputs` — a module a step type's class includes, after `EasyFlow::Step`, to declare the list of named inputs an admin fills in, each a fixed value, an output of an earlier step, or the id of the run's owner. `EasyFlow::Inputs.values_of(node, state, run: run)` returns those values as a hash with string keys, reading a step reached more than once at its latest visit.
21
22
  - `host.allowed_answers=` — set on a host to a lambda given a step and the answers recorded so far, returning the answers that step may take in this run: several narrows the answers shown, one is recorded without showing the step, and none records a blank and skips it.
22
23
  - `EasyFlow::FlowsController` — the visitor controller; the app subclasses it to serve one host's flows from its own routes and to change what happens at the start, on each step and at the finish.
@@ -24,7 +25,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
24
25
  - `routed_by` — class method on a `FlowsController` subclass naming the prefix of the app's own route names that the controller redirects and links to.
25
26
  - `run_address` — private method a `FlowsController` subclass overrides to give the value put in a run's address in place of its id.
26
27
  - `find_run` — private method a `FlowsController` subclass overrides to find a run, among the host's own runs, from the value in its address.
27
- - `EasyFlow::Run` — the stored record of one visitor's pass through a flow, started with `EasyFlow::Run.start` on the live version or a chosen published one and pinned to that version, moved on past a waiting step with `advance`, read for the output its flow ended with by `output`, for the mark of the End it reached by `end_mark`, for whether it ended at an End step by `ended_at_end?`, for the step a loop stopped it at by `stopped_on_loop`, for when each step visit was completed by `completed_at` and for the time a Wait step holds it until by `held_until`, and linked to the runs its Flow steps started by `inner_runs`, to the one it is waiting on by `waiting_on`, and to the run that started it by `parent_run`.
28
+ - `EasyFlow::Run` — the stored record of one visitor's pass through a flow, started with `EasyFlow::Run.start` on the live version or a chosen published one and pinned to that version, moved on past a waiting step with `advance`, read for the output its flow ended with by `output`, for the mark of the End it reached by `end_mark`, for whether it ended at an End step by `ended_at_end?`, for the step a loop stopped it at by `stopped_on_loop`, for when each step visit was completed by `completed_at` and for the time the step it is stopped at holds it until by `held_until`, and linked to the runs its Flow steps started by `inner_runs`, to the one it is waiting on by `waiting_on`, and to the run that started it by `parent_run`.
28
29
  - `easy_flow_run_view(version, steps:, selected: nil, ended_at: nil, start_and_end: true)` — a view helper every view in the app can call, drawing a read-only view of one flow version's steps with the state, status line, version and address the app supplies for each step, and the Start and End steps unless the app hides them.
29
30
  - `EasyFlow::QuestionRunner` — reads a flow document: its steps, the next step for a set of answers and the times their steps were completed, the answers on the path taken, and a question's text and an answer's label.
30
31
 
@@ -112,6 +113,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
112
113
  - The blocks of `shows_values`, `shows_code` and `links_to` are called every time the canvas is drawn, so they must not be slow and must not change anything. When the block of `summarizes_by`, `shows_values`, `shows_code` or `links_to` raises an error, the canvas still opens, that step is drawn without the summary, sections or links that failed, and the error is written to the app's log. Ask the developer what an admin should read about a step of this type in its settings without being able to change it, and which pages it should link to.
113
114
  - `awaits_input` — the visitor is shown this step and submits an answer to it.
114
115
  - `waits_until { |node, state| ... }` or `waits_until { |node, state, times| ... }` — the run stops at this step until the block returns a truthy value. See step 8.
116
+ - `holds_until { |node, state, times| ... }` — the time a run stopped at this step is held until, or `nil` when it is not known. See step 8.
115
117
  - `answer_check { |node, value| ... }` — checks a submitted answer before it is recorded. `value` is the submitted string, an array of strings when the input submits several values, or `nil` or `""` when the input sent nothing. An array may hold blank strings. Return a message to refuse the answer, or `nil` to accept it. Without it every answer is accepted, including a blank one. For a file input, see step 7.
116
118
  - `labels_answer_by { |node, value| ... }` — the label a recorded answer to a step of this type is shown by. `value` is one recorded answer, and for an array answer the block is called once per entry. Return the label, or `nil` or `""` to fall back to the label of the question answer with that value, and then to the value itself. The block is called on every completion page and every `choice_label` call, so it must not be slow and must not change anything. Ask the developer what a visitor or admin reading the answer should see in place of the stored value.
117
119
  - `ends_here` / `begins_here` — marks the type as an end or a start of a flow. A run that ends on a step of an `ends_here` type gives that step's `output` setting as `run.output`, so a type of the app's own that ends a flow declares `setting :output, type: :string` for the admin to fill in, or gives no output.
@@ -302,6 +304,18 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
302
304
  - While the block returns a falsy value, the visitor is shown `Waiting for <name>.` and no form, no Next button and no Back button. `<name>` is what `names_by` gives, or for a type that declares `chooses_flow` the chosen flow's title and version, or the `step_name` when there is neither, so give the type a name a visitor can read.
303
305
  - In a flow that keeps no stored run, the waiting page also shows a `Check again` button that loads the page again with the answers and the times their steps were completed.
304
306
  - Once the block returns a truthy value, `true` is recorded under the step's id, or the value `process` returns when the type also defines `process`, and the run goes on to the next step.
307
+ - When what the step waits for is a time the step can work out, also declare `holds_until` with a block that returns that time, so the app can read it with `run.held_until`:
308
+
309
+ ```ruby
310
+ holds_until { |node, state, _times| Invoice.due_at(state[node.config["invoice_step"]]) }
311
+ ```
312
+
313
+ Here `Invoice.due_at` is the app's own lookup, returning a time or `nil`.
314
+
315
+ - The block is given `node`, `state` and `times` as the `waits_until` block is. It returns a time, or `nil` when the time is not known yet.
316
+ - It only reports the time. The run still waits until the `waits_until` block returns a truthy value, so a step that should move on once its time has passed checks that time in `waits_until` as well.
317
+ - Each time the visitor loads a stored run's page or the app calls `run.advance`, and the run is left stopped at a step whose block returns a time, the app's hook for held runs, if `easy_flow-install` set one, is called with the run and that time.
318
+ - Ask the developer whether the step's time can be worked out from its settings, the answers and the times. When it cannot, declare no `holds_until`, and `run.held_until` is `nil` at that step.
305
319
  - Do not declare `awaits_input` on a type that waits. The waiting message replaces the form, so the input is never shown.
306
320
  - The page does not reload itself. Ask the developer how the run should move on when what it waits for happens:
307
321
  - The visitor reloads the page, or presses `Check again` in a flow that keeps no stored run. This needs nothing more, and works whether or not the flow keeps a stored run.
@@ -552,7 +566,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
552
566
  - Without a date, the run is held for as long as the counted step has no time, such as a step that only routes or a step not on the path taken.
553
567
  - While held, the visitor is shown `Waiting for <name>.`, such as `Waiting for 30 minutes after ask.`, with no form, no Next button and no Back button.
554
568
  - Once the time has passed, `true` is recorded under the step's id and the run goes on, when the visitor next loads the page or the app calls `run.advance`, the same as any waiting step. The page does not reload itself. Ask the developer how the run should move on, as in step 8 of "Declare a step type", such as a job the app schedules for `run.held_until` that calls `run.advance`.
555
- - `run.held_until` gives the time a stored run stopped at a Wait step is held until, or `nil` when it is not stopped at a Wait step or the time is not known yet.
569
+ - `run.held_until` gives the time a stored run stopped at a Wait step is held until, or `nil` when the time is not known yet. The same holds at a step of any type that declares `holds_until`; see step 8 of "Declare a step type".
556
570
  - In a flow set to save on finish or to save nothing, the waiting page also shows a `Check again` button, which loads the page again with the answers and the times their steps were completed, so the Wait moves on once its time has passed. Reloading the page in the browser instead takes the completion time of the step just submitted again, so a Wait counting minutes or a time of day from that step does not move on by reloading. Ask the developer whether such a flow needs to be set to save each step.
557
571
  4. Publish a flow set to save each step with a Wait step counting a few minutes from a question, walk it to the Wait step, check the page shows `Waiting for <minutes> minutes after <question id>.` and `run.held_until` is that many minutes after the answer, and check `run.advance` after that time moves the run on. In a flow set to save nothing, walk to the same Wait step, wait past the time, press `Check again`, and check the next step is shown.
558
572
 
@@ -592,20 +606,26 @@ Use this when a visitor's run should stop until a set time has passed, such as a
592
606
  1. Ask the developer which earlier step records the list, and under which of its outputs. The list must be recorded as an array, such as `{ "variants" => ["short", "long"] }`.
593
607
  2. On the canvas, place a For each step and fill in its settings:
594
608
  - `List` — the earlier step and its output as text, `<step>.<output>`, such as `outline.variants`, or the step id alone when it records the array as its plain value.
595
- - `Concurrency` — how many items may run at the same time. It is saved and shown in the box's header, and items still run one after another.
596
- - `On item failure` — `continue` or `stop`. It is saved and shown in the box's header, and a failed item still lets the next item start.
609
+ - `Concurrency` — how many items may be unfinished at the same time. With none set, items run one at a time.
610
+ - `On item failure` — `continue` or `stop`. Under `continue` a failed item ends only that item. Under `stop` no item starts after an item has failed, the items already running are allowed to end, and the run then leaves on the `failed` connection of the held step that failed.
611
+ - `Most items` — stored as `item_limit`, the most items the list may hold. With none set, the limit is 100.
597
612
  3. Drag the steps to run per item into the box. Connect the For each step to the first held step, connect the held steps to each other, and connect the last held step to the step after the box.
598
613
  4. Publish the flow set to save each step. A For each step reached in a flow set to save on finish or to save nothing shows the visitor `Steps can only be run for each item in a flow that saves its runs.` and goes no further, at the For each step or at any step it holds.
599
614
  5. What then holds when a stored run reaches the For each step:
600
- - The run walks the held steps for item 1, then item 2, and so on in list order, one item at a time.
615
+ - The run starts items in list order and keeps no more than `concurrency` of them unfinished at once. An item counts as running once one of its held steps has a recorded visit.
601
616
  - Each visit of a held step is recorded under `<step>@item<n>`, counting items from 1, such as `write@item2`. A held step visited again inside one item, such as after a `retry` connection back to itself, is recorded as `<step>@item<n>@<visit>`, such as `write@item2@2`, and other items' visits are left as they were.
602
- - `run.next_step(run.recorded)` returns the held step to run next with that key as its `id`, so the app records its value with `run.record(step.id, value)` and reads its inputs with `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
617
+ - `run.next_step(run.recorded)` returns one held step to run next with that key as its `id`, so the app records its value with `run.record(step.id, value)` and reads its inputs with `EasyFlow::Inputs.values_of(step, run.recorded.stringify_keys, run: run)`.
618
+ - `run.ready_steps` returns every step that may run now: the next held step of each unfinished item, up to `concurrency` of them, and outside a For each step the next step alone. An app that hands out several steps at once reads this list, and an app that reads only `next_step` keeps working one item at a time. `run.advance` runs every acting step among them.
603
619
  - An item ends when its walk leaves the box, or when a held step's `route` returns `"failed"`, and the next item starts.
604
- - Once every item has ended, `run.advance` records the For each step's own value under its id: `result` is `"passed"` when no item failed and `"failed"` otherwise, `items` is an array with one hash per item mapping each held step it reached to that step's latest value for the item, and `passed` and `failed` count the items.
605
- - A list that is missing, is not an array or is empty runs no items, records `items` as `[]`, and the run goes on to the step after the box.
620
+ - Once every item has ended, `run.advance` records the For each step's own value under its id: `result` is `"passed"` when no item failed and `"failed"` otherwise, `items` is an array with one hash per item that ran mapping each held step it reached to that step's latest value for the item, and `passed` and `failed` count the items.
621
+ - An empty list runs no items, records `items` as `[]`, and the run goes on to the step after the box.
622
+ - A list that is missing, is not an array, or holds more items than the limit starts no item and records `{ "result" => "failed", "reason" => ..., "items" => [], "passed" => 0, "failed" => 0 }`. The reason names the step and output, the value's kind (text, a number or a hash), or the limit. The run then leaves on a `failed` connection leaving the box from a held step, and with none it stops there, as after any failed step with no `failed` connection.
623
+ - A run that reaches the For each step again, through a later step looping back, runs the held steps again for each item of the list as it stands then. The second pass's visits are keyed `<step>@item<n>@pass2`, or `<step>@item<n>@pass2@<visit>` for a further visit, and the first pass's keys carry no pass. Each pass's outputs are recorded under the For each step's own visit, such as `variants` and `variants@2`, and a step after the box reads the latest pass.
606
624
  - A step after the box reads `result`, `items`, `passed` or `failed` through an input naming the For each step and that output.
607
625
 
608
626
  ```ruby
627
+ run.ready_steps.map(&:id)
628
+ # => ["write@item2", "write@item3", "write@item4"]
609
629
  step = run.next_step(run.recorded)
610
630
  step.id
611
631
  # => "write@item2"
@@ -623,7 +643,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
623
643
  2. Read from a run:
624
644
  - `run.recorded` — the answers so far, a hash keyed by step id as symbols. A value is a string, or an array of strings for a checklist or any step that takes several answers, empty when nothing was ticked. A File upload step's value is the reference the host's file store returned, not the file, and a step of the app's own that took several files holds an array of references, so the app reads each file back from its own store.
625
645
  - `run.completed_at` — the time each step visit was completed, a hash keyed the same as `run.recorded`, each value a time in the app's time zone, including each later visit under `:"<id>@<n>"`. A value recorded before the engine kept times has no time, so its key is missing. See "Read when steps were completed".
626
- - `run.held_until` — the time the run is held until while stopped at a Wait step, or `nil`. See "Hold a run until a time".
646
+ - `run.held_until` — the time the run is held until, given by the `holds_until` block of the type of the step it is stopped at, such as a Wait step. It is `nil` when the run is not stopped at a step, the step's type declares no `holds_until`, or the block returns `nil`. See "Hold a run until a time".
627
647
  - `run.flow` — the flow it belongs to.
628
648
  - `run.owner` — the optional record the run belongs to, polymorphic, set by the app. `run.label` and `run.status` are free string columns for the app's own use.
629
649
  - `run.parent_run` and `run.parent_step` — the run whose Flow step started this one and that step's id, both `nil` for a run a visitor or the app started. Once this run ends with an output, `run.parent_run.recorded` holds that `output` under that step id. When it ends with none, nothing is recorded there. When a loop stops it, nothing is recorded there and no job is queued. When an admin removed the flow the parent run belonged to, `parent_run` is `nil` and `parent_step` still holds the step id.
@@ -683,7 +703,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
683
703
  - A run starts only on a version its own flow has published and not retired or withdrawn, and any other version raises `ActiveRecord::RecordInvalid`.
684
704
  - Always read a run against `run.pinned_definition`, never the flow's live version, since a run keeps the version it started on after a new one is published.
685
705
  - Always look flows and runs up through a host.
686
- - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, and a step held by a For each step is keyed `<id>@item<n>` or `<id>@item<n>@<visit>`, so code that reads answers never assumes one answer per step id, and takes the part of a key before the first `@` to find its step.
706
+ - In a flow that loops, a later visit's answer is keyed `<id>@<n>`, and a step held by a For each step is keyed `<id>@item<n>`, `<id>@item<n>@<visit>`, or with `@pass<n>` after the item on a later pass, so code that reads answers never assumes one answer per step id, and takes the part of a key before the first `@` to find its step.
687
707
  - A Count step and any code that reads every visit of a step together count a held step's visits across all items. A step id may not contain `@`, and a flow with one is refused when published.
688
708
  - A loop that comes back to a step with no answer given since the last visit to it ends the flow there and `run.stopped_on_loop` names that step, so every loop needs a step that awaits input.
689
709
  - `run.ended_at_end?` is `true` only for a run whose last step reached is of an `ends_here` type, so a run a loop stopped, or one that ended at a step with no connection to follow, is never counted as ended at an End step.
@@ -700,6 +720,7 @@ Use this when a visitor's run should stop until a set time has passed, such as a
700
720
  - A runner the app builds reads times only when handed `times: run.completed_at`.
701
721
  - A Wait step without a date holds the run for as long as the step it counts from has no time.
702
722
  - A type that waits never also declares `awaits_input`.
723
+ - A `holds_until` block only reports a time and never moves a run on, which only `waits_until` does.
703
724
  - `run.advance` only moves a stored run, and never finishes it; the visitor's next page load does.
704
725
  - A flow's output is free text an admin writes on each End step, so code that acts on it handles `nil` and any value it does not expect.
705
726
  - A flow's output is read from a stored run only, so a flow the admin set to save nothing gives none.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-info
3
- description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, flows that loop back to ask a step again, a loop that stops a run when nothing new was answered and the step it came back to, whether a run ended at an End step, hosts and the step types each offers its admins, runs and the published version each starts on, each visit a run records with its value and the time the step was completed, and the output a flow gives when it ends, the built-in step types including questions and checklists that can require an answer and explain each answer behind an info button, file upload steps that hand a visitor's file to the app's file store and read it back by its name, and branching on an answer, including one named output of a step that recorded several, on comparing a number with an amount, or on comparing two earlier answers or one earlier answer with an amount alone, steps flagged when they name an earlier step without choosing which of its outputs to read, branching on a list of such comparisons that must all hold or of which any one must hold, branching on the hour, weekday or minute a step was completed, Wait steps that hold a run until a number of minutes or a time of day after an earlier step was completed, or until a date, and are named after what they wait for, the Check again button a visitor sees at a waiting step in a flow that keeps nothing, Count steps that count how often an earlier step was answered so a loop can give up after a number of tries, Flow steps that name another flow, open its canvas when their card is clicked with a button back to the flow it was opened from, start a run of it for the same owner when a stored run reaches them, are flagged when the flow or version they name cannot run or leads back to the flow they sit in, let the waiting run name that inner run, move that run on along the output it ends with, leave it waiting when the inner run is stopped by a loop, and fail with an error naming the step when its version was taken out of service or its inner run ended with no output, removing a flow and why it is refused while a waiting run depends on it, step types the host app registers, including ones whose outputs are named by the entries an admin lists in one of their settings, ones that start another flow and work out which flow and version to run from their own settings and are named after that flow, or choose it from the run they are in, the answers a host allows a step in a run and the steps it fills in or passes over, the checks they make on an answer, what a step shows a visitor and how that can depend on the visitor's run, and steps that hold a run until something outside the flow has happened, group steps drawn as a box an admin drags steps into and out of, the For each step that runs the steps its box holds once per item of a list and records each item's values and how many passed and failed, and the settings an admin fills in, including picks whose options come from the app's data, choices drawn as radio cards with a hint under each, and settings kept on one of the app's own records.
3
+ description: Use to learn what easy_flow offers — guided flows an admin draws on a canvas and a visitor runs one step at a time, versioned documents of steps and connections, flows that loop back to ask a step again, a loop that stops a run when nothing new was answered and the step it came back to, whether a run ended at an End step, hosts and the step types each offers its admins, runs and the published version each starts on, each visit a run records with its value and the time the step was completed, and the output a flow gives when it ends, the built-in step types including questions and checklists that can require an answer and explain each answer behind an info button, file upload steps that hand a visitor's file to the app's file store and read it back by its name, and branching on an answer, including one named output of a step that recorded several, on comparing a number with an amount, or on comparing two earlier answers or one earlier answer with an amount alone, steps flagged when they name an earlier step without choosing which of its outputs to read, branching on a list of such comparisons that must all hold or of which any one must hold, branching on the hour, weekday or minute a step was completed, Wait steps that hold a run until a number of minutes or a time of day after an earlier step was completed, or until a date, and are named after what they wait for, the Check again button a visitor sees at a waiting step in a flow that keeps nothing, Count steps that count how often an earlier step was answered so a loop can give up after a number of tries, Flow steps that name another flow, open its canvas when their card is clicked with a button back to the flow it was opened from, start a run of it for the same owner when a stored run reaches them, are flagged when the flow or version they name cannot run or leads back to the flow they sit in, let the waiting run name that inner run, move that run on along the output it ends with, leave it waiting when the inner run is stopped by a loop, and fail with an error naming the step when its version was taken out of service or its inner run ended with no output, removing a flow and why it is refused while a waiting run depends on it, step types the host app registers, including ones whose outputs are named by the entries an admin lists in one of their settings, ones that start another flow and work out which flow and version to run from their own settings and are named after that flow, or choose it from the run they are in, the answers a host allows a step in a run and the steps it fills in or passes over, the checks they make on an answer, what a step shows a visitor and how that can depend on the visitor's run, and steps that hold a run until something outside the flow has happened, the time a waiting step holds a run until and the call the app gets each time a stored run is left held until that time, group steps drawn as a box an admin drags steps into and out of, the For each step that runs the steps its box holds once per item of a list and records each item's values and how many passed and failed, and the settings an admin fills in, including picks whose options come from the app's data, choices drawn as radio cards with a hint under each, and settings kept on one of the app's own records.
4
4
  tools: Read
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -17,14 +17,14 @@ Reach for it when an app needs a questionnaire, an intake form, or any decision
17
17
 
18
18
  easy_flow declares no commands of its own for this local. Its surface is split between the other two:
19
19
 
20
- - **easy_flow-install** owns putting the engine into an app: its migrations, mounting it, choosing the controller it inherits from, naming hosts and the step types each one offers, choosing the default step drawing, setting the file store that keeps uploaded files, the flow checks, and the admin pages.
21
- - **easy_flow-develop** owns building on it: declaring and registering step types, including ones that read an answer back under a label of their own, ones whose outputs are named by the entries an admin lists in one of their settings, ones that wait, ones whose waiting or routing rule reads the times steps were completed, ones that start another flow, ones that hold other steps in a box on the canvas, and ones with settings kept on the app's own records, narrowing the answers a host allows a step in a run, moving a run on once what it waits for has happened, serving a host's flows from the app's own controllers and routes, and starting a run on a chosen published version, reading a visitor's run, its answers, the times its steps were completed, the inner run it is waiting on, the time a Wait step is holding it until, the output its flow ended with, whether it ended at an End step, and the step a loop came back to when it stopped the run.
20
+ - **easy_flow-install** owns putting the engine into an app: its migrations, mounting it, choosing the controller it inherits from, naming hosts and the step types each one offers, choosing the default step drawing, setting the file store that keeps uploaded files, having the app told when a stored run is left held until a time, the flow checks, and the admin pages.
21
+ - **easy_flow-develop** owns building on it: declaring and registering step types, including ones that read an answer back under a label of their own, ones whose outputs are named by the entries an admin lists in one of their settings, ones that wait, including ones that say the time they hold a run until, ones whose waiting or routing rule reads the times steps were completed, ones that start another flow, ones that hold other steps in a box on the canvas, and ones with settings kept on the app's own records, narrowing the answers a host allows a step in a run, moving a run on once what it waits for has happened, serving a host's flows from the app's own controllers and routes, and starting a run on a chosen published version, reading a visitor's run, its answers, the times its steps were completed, the inner run it is waiting on, the time the step it is stopped at holds it until, the output its flow ended with, whether it ended at an End step, and the step a loop came back to when it stopped the run.
22
22
 
23
23
  ## How to use it
24
24
 
25
- - To get easy_flow running in an app, or to change how it is configured, including which step types a host's admins can add and where uploaded files are kept, use **easy_flow-install**.
25
+ - To get easy_flow running in an app, or to change how it is configured, including which step types a host's admins can add, where uploaded files are kept, and having the app told when a stored run is left held until a time, such as to schedule a job that moves it on then, use **easy_flow-install**.
26
26
  - To ask a visitor for a file, an admin places a file upload step on the canvas, and the app must first have a file store set through **easy_flow-install**.
27
- - To add a step type, give a step type its own rule for refusing an answer, give it its own way to read an answer back, name a step type's outputs after the entries an admin lists in one of its settings, make what a step shows depend on the visitor's run, hold a run until something outside the flow has happened, make a step type's waiting or routing rule read the times steps were completed, read the time a Wait step is holding a run until, add a step type of the app's own that starts another flow, including one that chooses the flow from the run it is in, limit which answers a step offers in a run from the answers given so far, keep a step's setting on one of the app's own records, put a flow on the app's own pages, start a run on a published version other than the live one, act on what a visitor answered or when each step was completed, act on the output a visitor's flow ended with, or tell a run that ended at an End step from one a loop stopped, use **easy_flow-develop**.
27
+ - To add a step type, give a step type its own rule for refusing an answer, give it its own way to read an answer back, name a step type's outputs after the entries an admin lists in one of its settings, make what a step shows depend on the visitor's run, hold a run until something outside the flow has happened, make a step type's waiting or routing rule read the times steps were completed, make a waiting step type of the app's own say the time it holds a run until, read the time a run is held until, add a step type of the app's own that starts another flow, including one that chooses the flow from the run it is in, limit which answers a step offers in a run from the answers given so far, keep a step's setting on one of the app's own records, put a flow on the app's own pages, start a run on a published version other than the live one, act on what a visitor answered or when each step was completed, act on the output a visitor's flow ended with, or tell a run that ended at an End step from one a loop stopped, use **easy_flow-develop**.
28
28
  - To give a flow a different output for each way it can end, no code is needed: an admin fills in the output on each End step on the canvas.
29
29
  - To branch a flow on an answer or on a number the visitor gave, no code is needed: an admin places one of the built-in branching steps on the canvas.
30
30
  - To branch a flow on how two earlier answers compare, such as whether a second reading is higher than the first, no code is needed: an admin places a Compare two values step on the canvas.
@@ -36,7 +36,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
36
36
  - To let a visitor tick several answers on one step, no code is needed: an admin places a checklist step on the canvas.
37
37
  - To explain an answer to the visitor, no code is needed: an admin fills in that answer's info on a question or checklist step.
38
38
  - To start another flow from inside a flow, no code is needed: an admin places a Flow step on the canvas and picks that flow and its version. The connections leaving the step are labelled with the ways that flow can end, and a stored run moves on along the one named after the output its inner run ended with. Clicking the step's card opens the canvas of the flow it runs, and that canvas has a button back to the flow it was opened from. A Flow step cannot start the flow it sits in, directly or through other flows.
39
- - To run some steps once for each item of a list an earlier step recorded, no step type is needed: an admin places a For each step on the canvas, names the list as `<step>.<output>`, and drags the steps into its box. A stored run walks the held steps for each item in list order, one item at a time, records each visit under `<step>@item<n>`, and once every item has ended records the For each step's `result`, `items`, `passed` and `failed`, which later steps read as inputs. A flow that keeps nothing refuses to run it. Reading those keys from the app's own code is in **easy_flow-develop**.
39
+ - To run some steps once for each item of a list an earlier step recorded, no step type is needed: an admin places a For each step on the canvas, names the list as `<step>.<output>`, and drags the steps into its box. A stored run starts items in list order, keeps up to the step's concurrency of them unfinished at once and names every step ready now through `run.ready_steps`, records each visit under `<step>@item<n>`, and once every item has ended records the For each step's `result`, `items`, `passed` and `failed`, which later steps read as inputs. Under the `stop` rule no item starts after one fails. A list that is missing, is not a list or is longer than the step's item limit, 100 unless set, fails the step with a `reason`. A run that reaches the step again runs its items again as a new pass keyed `<step>@item<n>@pass<n>`. A flow that keeps nothing refuses to run it. Reading those keys from the app's own code is in **easy_flow-develop**.
40
40
  - To add another step type that holds other steps, use **easy_flow-develop**. Once one is offered, an admin places it on the canvas and drags steps into its box, with no further code.
41
41
  - To ask a step again, such as repeating a question until the visitor says they are done, no code is needed: an admin connects a later step back to an earlier one on the canvas.
42
42
  - To end a loop after a number of tries, no code is needed: an admin places a Count step after the step being repeated and a Compare step after the Count step, and connects the Compare step's false connection back to the repeated step.
@@ -83,7 +83,7 @@ easy_flow declares no commands of its own for this local. Its surface is split b
83
83
  - **Input** — a named value a Read data or Write data step passes to the app, either a fixed value, an output of an earlier step, or the id of the run's owner, which an admin chooses by ticking `The run's owner`. A step reached more than once gives its most recent output. A flow that saves no runs, or a run with no owner, gives no value for the run's owner, and a run started by a Flow step has its parent's owner.
84
84
  - **Completion time** — the time a step was completed, kept for every visit beside the value that visit recorded. Every step that records a value has one, including steps that act on their own and waiting steps, not only steps a visitor answers. A stored run saves it with the run. A flow that carries its answers in the page carries each completion time in the page too, gives a value sent without a time the time it arrived, and drops a time it cannot read. A run stored when such a flow finishes keeps the completion times of the visits on its path. Going back discards the last visit's completion time with its value.
85
85
  - **Completion time outputs** — three outputs every step that records a value offers beside its own: "Hour completed", the hour from 0 to 23 in the app's time zone, "Weekday completed", from 1 for Monday to 7 for Sunday, and "Minutes since 1970 when completed", the whole minutes since the start of 1 January 1970 in UTC. Each is read from the completion time of the latest visit to that step, and a step with no completion time has none of them. Compare, Compare two values and All of or Any of read them, so Compare two values with "more than" and an amount of 30 on two steps' minutes is true when the first step was completed more than 30 minutes after the second. Condition and Count list them among a step's outputs but do not read the time when one is picked.
86
- - **Wait** — a built-in waiting step that holds a run until a time. The admin picks the earlier step it counts from and gives a number of minutes after it, a time of day as HH:MM, or a date as YYYY-MM-DD. A date holds the run until the start of that day in the app's time zone and wins over the other two, and it holds even when the earlier step has no completion time. Otherwise a time of day holds the run until the next time that time of day comes after the earlier step's completion time, the same day when it is still to come and the next day when it is not, and it wins over minutes. With neither, the run is held for the minutes after the earlier step's completion time, and blank minutes hold it not at all. While the earlier step has no completion time and no date is set, the run stays held. It is counted from the completion time of the latest visit to that step. Like any waiting step, once its time has come the run moves past it the next time the visitor's page is loaded or the app moves the run on.
86
+ - **Wait** — a built-in waiting step that holds a run until a time. The admin picks the earlier step it counts from and gives a number of minutes after it, a time of day as HH:MM, or a date as YYYY-MM-DD. A date holds the run until the start of that day in the app's time zone and wins over the other two, and it holds even when the earlier step has no completion time. Otherwise a time of day holds the run until the next time that time of day comes after the earlier step's completion time, the same day when it is still to come and the next day when it is not, and it wins over minutes. With neither, the run is held for the minutes after the earlier step's completion time, and blank minutes hold it not at all. While the earlier step has no completion time and no date is set, the run stays held. It is counted from the completion time of the latest visit to that step. Like any waiting step, once its time has come the run moves past it the next time the visitor's page is loaded or the app moves the run on. The time it holds a run until is that run's held-until time.
87
87
  - **Wait step name** — what a Wait step is called on its canvas card and in the "Waiting for" line a visitor sees, following the same order as the rule that holds the run. A date set names it by that date, such as "2026-12-01". Otherwise it is named by the time of day, or by the minutes followed by "minutes", then "after" and the earlier step, such as "09:00 after signup" or "30 minutes after signup", with "minute" in place of "minutes" when the number is 1, such as "1 minute after signup". A Wait step with no date, time of day or minutes has no name of its own, so its canvas card shows the step's id and the visitor sees "Waiting for Wait".
88
88
  - **Count** — a built-in step that acts on its own and records a whole number: how many visits to an earlier step the run has recorded. When the admin picks an answer, only visits that gave that answer are counted, and when the admin picks none, every visit is counted. The admin picks which of the earlier step's outputs the answer is read from, as described under chosen output. On the canvas the step is named "Count" followed by the earlier step and the answer it counts, such as "Count tests failed". Each visit to a Count step in a loop records a new count under its own visit key, so a Compare step after it can end the loop once the count reaches an amount.
89
89
  - **Flow step** — a built-in step that names another flow and the number of one of its versions. The admin picks the flow from the same host's flows, listed by title as the admin's list of flows shows them. The step has one connection for each different output the End steps of that version write, and none when no flow or version is picked or no End step there has an output. On the canvas its card is named after the flow's title and the version, such as "Onboarding, version 2", and is marked "Runs a flow". Once a flow is picked, clicking the card opens that flow's canvas, and the card's Settings button opens the step's own settings instead. A canvas opened from a Flow step's card shows a "Back to" button named after the title of the flow it was opened from, or its slug when it has no title, which returns to that flow's canvas. The button only appears when that flow belongs to the same host, and to the same owner when the host has one. While the admin is connecting steps, clicking the card picks it as the connection's target. A run that reaches a Flow step stops there. When the run is a stored run, it starts one inner run of the named flow on the picked version, and a visitor on the run's page is taken to that inner run's first unanswered step. A run that carries its answers in the page, and an admin's preview, stop at the Flow step, start no run, and never move past it.
@@ -95,6 +95,8 @@ easy_flow declares no commands of its own for this local. Its surface is split b
95
95
  - **Inner run** — the run a Flow step starts. It records which run started it and at which step, and that run holds at most one inner run for each Flow step, however often it is moved on. It belongs to the same owner as the run that started it. When the picked version has been retired or withdrawn, no inner run is started and the run that reached the Flow step fails with an error naming that step. While the run that started it is stopped at the Flow step, that run can name the inner run it is waiting on, and it names none when it is stopped at any other step or has finished. Its steps that act on their own run as soon as it starts, and it stops at its first step that asks for input or waits.
96
96
  - **Handing back** — what happens when an inner run ends. Its flow output is recorded in the run that started it, as that run's answer at the Flow step, and a background job then moves that run on along the connection labelled with the output. The inner run's visitor is taken back to the run that started it, whose page moves it on without waiting for the job and shows its next step. An inner run that ended with no output records nothing in the run that started it, and the background job then fails with an error naming the Flow step, so that run does not move on. An inner run that a loop stopped hands nothing back and starts no background job, so the run that started it stays stopped at the Flow step and still names that inner run as the one it is waiting on. An output is handed back only once, so an inner run moved on again after it ended changes nothing. Because the move otherwise happens in a background job, the app must run its jobs for a run nobody is visiting to go past a Flow step.
97
97
  - **Waiting step** — a step whose type carries a rule saying whether what it waits for has happened, such as a payment clearing or a document being signed. A run that reaches it stops there, and the visitor sees "Waiting for" followed by the step's name, with no form to submit. Once the rule says it has happened, the run moves past the step the next time the visitor's page is loaded or the app moves the run on, and the step is recorded as `true`.
98
+ - **Held-until time** — the time a waiting step says it holds a run until, worked out from the step, the answers so far and their completion times. The Wait step gives one, and a waiting step type of the app's own gives one only when it declares how to work it out. A stored run gives the held-until time of the step it is stopped at, and gives none when it has finished, or when it is stopped at a step that gives no time.
99
+ - **Held notice** — a call the app may set up to be told, with the run and its held-until time, each time easy_flow moves a stored run on and leaves it stopped at a step with a held-until time. The app can use it to move the run on once that time comes, so a run nobody is visiting goes past a Wait step. It is called again on every such move, not only the first. A flow that carries its answers in the page, a finished run, and a run stopped at a step with no held-until time are never reported. With none set, nothing is called and runs move on as before.
98
100
  - **Check again** — a button a visitor sees under the "Waiting for" line in a flow that carries its answers in the page. It loads the step page again with the answers and their completion times, so the run moves past a waiting step whose rule now says it has happened, such as a Wait step whose time has come. A stored run shows no such button, since loading its page again does the same.
99
101
  - **Group step** — a step whose type is declared as holding steps, such as an app's own "for each" step. The canvas draws it as a dashed box with a header line at the top and the steps it holds inside. The header line is the step type's code followed by each filled-in setting as `name: value`, or `name value` for a number setting, joined by ` · `. It sits right above the first step the box holds, and the connection from the group step to a step it holds is not drawn. A host that hides step type codes shows the type's name and the settings' labels instead. Clicking the header opens the step's settings, and a connection drawn into a group step ends at the top of its box.
100
102
  - **Holding a step** — an admin puts a step in a group step by dragging it onto the group's box, and takes it out by dragging it onto the canvas outside the box. Moving a step in or out changes only which steps the group holds and leaves every connection as it was. The group step lists the ids of the steps it holds under `holds` in the flow's document. Removing a step takes it out of the group that held it, and a step cannot be put in itself or in a step whose type does not hold steps, and a group step cannot be put in another group step. A run reaching a group step passes straight on along its connection, and the steps it holds run once like any other steps.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: easy_flow-install
3
- description: Use to hook easy_flow into a project — copying and running its migrations, mounting the engine for each host, setting the controller it inherits from, declaring hosts with their layouts, access methods, the record that owns their flows and the step types each offers, choosing the default step drawing, setting the file store that keeps files visitors upload, turning on optional checks, setting the time zone Wait steps and step completion times are read in, giving the app a job queue that moves a run on once the flow its Flow step, or its own step type that starts a flow, started ends, and reaching the admin pages.
3
+ description: Use to hook easy_flow into a project — copying and running its migrations, mounting the engine for each host, setting the controller it inherits from, declaring hosts with their layouts, access methods, the record that owns their flows and the step types each offers, choosing the default step drawing, setting the file store that keeps files visitors upload, turning on optional checks, setting the time zone Wait steps and step completion times are read in, giving the app a job queue that moves a run on once the flow its Flow step, or its own step type that starts a flow, started ends, setting what the app is told when a saved run is held until a time, and reaching the admin pages.
4
4
  tools: Bash, Read, Edit
5
5
  scope: guided flows — versioned documents of steps and the connections between them, drawn on a canvas by an admin and run by a visitor one step at a time, with step types the host registers
6
6
  ---
@@ -21,6 +21,7 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
21
21
  - `EasyFlow.file_store` — the object that keeps a file a visitor uploads at a File upload step and names it again later. Defaults to none, and with none set an uploaded file is refused with `EasyFlow::NoFileStore`.
22
22
  - `EasyFlow.picture_store` — the object that keeps a picture an admin adds to a question step on the canvas, for the flow it belongs to, and gives the address the picture is loaded from. Defaults to none, and with none set an admin who chooses a picture is told pictures cannot be added yet.
23
23
  - `EasyFlow.data_source` — the object that says what Read data and Write data steps can read and write, and carries each one out. Defaults to none, and with none set those steps offer no choices.
24
+ - `EasyFlow.on_held` — a callable the engine calls with a saved run and the time it is held until, each time moving that run on leaves it stopped at a Wait step or at a step type of the app's own that declares a time it holds a run until. Defaults to none, and with none set nothing is called.
24
25
  - `EasyFlow.check` — turns on an optional flow check: `:unrouted_value`, `:unfollowed_path` or `:dead_end`.
25
26
  - `/manage/flows` — the admin pages, under each mount path, where flows are listed, created, drawn on the canvas, previewed and published.
26
27
 
@@ -127,7 +128,19 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
127
128
  12. Leave `EasyFlow.check` out unless the developer asks for it. The engine already turns on `:unrouted_value`, `:unfollowed_path` and `:dead_end` at boot. Any other name raises `EasyFlow::UnknownCheck` when the app boots.
128
129
  13. Check that the app loads Active Job (`require "rails/all"` or `require "active_job/railtie"` in `config/application.rb`) and has a queue adapter that runs jobs from the `default` queue. When a run started by a Flow step, or by a step type of the app's own that starts another flow, ends, the engine records its output in the run it was started from and queues a job on `default` that moves that run on. If no adapter runs that queue, the run that holds the step stays at it until its visitor next loads its page. If `config.active_job.queue_adapter` is not set for an environment, ask the developer which adapter to use there.
129
130
  14. Check `config.time_zone` in `config/application.rb`. A Wait step's time of day and date, and the "Hour completed" and "Weekday completed" outputs every completed step offers, are read in that zone, and with none set it is UTC. If it is not set, ask the developer which zone the app's admins mean when they write a time.
130
- 15. Start the server and open `<mount path>/manage/flows` for each host.
131
+ 15. Ask the developer whether a saved run held at a Wait step, or at a step type of the app's own that declares a time it holds a run until, should move on when its time comes with no visitor present. Without that, it moves on only when its visitor next loads its page. If it should, set a callable in the initializer that starts a job of the app's own at that time:
132
+
133
+ ```ruby
134
+ EasyFlow.on_held = ->(run, time) { AdvanceHeldRunJob.set(wait_until: time).perform_later(run) }
135
+ ```
136
+
137
+ - The callable is called with the run and the time it is held until. A Wait step's time is read in the zone from step 14.
138
+ - It is called every time moving a saved run on leaves the run held, which includes each load of the visitor's page while the run waits. The same run is passed again with the same time, so the job it starts must do nothing when the run has already moved on, and starting it twice must be safe.
139
+ - It is not called for a run the engine does not save, in a flow whose "What this keeps of a run" detail is "Nothing" or "The whole run once it finishes", for a run that has ended, or for a run stopped at a step that holds it until no time.
140
+ - It runs inside the request or the job that moved the run on, so slow work belongs in the job it starts, and an error it raises is raised there.
141
+ - The job needs the Active Job adapter from step 13 to run jobs at a set time. How the job moves the run on belongs to the `easy_flow-develop` local.
142
+ - Ask the developer whether the app already has a job that moves a run on, and point the callable at it. Do not write the job's logic.
143
+ 16. Start the server and open `<mount path>/manage/flows` for each host.
131
144
 
132
145
  ## Conventions
133
146
 
@@ -176,7 +189,8 @@ A Rails engine for flows an admin draws on a canvas and a visitor runs one step
176
189
  - After install, check that a Compare step, a Compare two values step, or a comparison of an All of or Any of step, once its earlier step is picked, offers "Hour completed", "Weekday completed" and "Minutes since 1970 when completed" beside that step's own outputs. They need no setting in the initializer.
177
190
  - After install, check that a Wait step placed on the canvas asks for the earlier step it counts from, minutes after it, a time of day as HH:MM and a date as YYYY-MM-DD. It needs no migration beyond the one that keeps each step's completion time with its value and no setting in the initializer beyond being listed in a host's `offers` when that host sets `offers`.
178
191
  - After filling in a Wait step, check its name on the canvas. With a date set it is named by the date alone, and the run waits until that date. Otherwise, with a time of day set, it is named by that time followed by "after" and the step it counts from, and the run waits until that time of day first comes after the step was answered. Otherwise it is named by the minutes, as "1 minute after" or "<n> minutes after" followed by the step it counts from, and the run waits that many minutes past the answer. With none of the three set it has no name of its own, and a visitor held at it sees "Waiting for Wait."
179
- - The engine queues no job for a Wait step. After publishing a flow with a Wait step, check that a visitor held at it sees "Waiting for" followed by the step's name, and that a stored run moves on when the visitor's page is loaded after its time has come. Moving a run on with no visitor present belongs to the `easy_flow-develop` local.
192
+ - The engine queues no job for a Wait step. After publishing a flow with a Wait step, check that a visitor held at it sees "Waiting for" followed by the step's name, and that a stored run moves on when the visitor's page is loaded after its time has come. To move it on with no visitor present, set `EasyFlow.on_held` as in step 15.
193
+ - After setting `EasyFlow.on_held`, publish a flow set to save each step with a Wait step counting a few minutes from a question, walk a run to the Wait step, and check that the callable is called with that run and the time the Wait step names. Then check that the job it started moves the run past the Wait step once that time has come, with no visitor loading the page.
180
194
  - After publishing a flow with a Wait step whose "What this keeps of a run" detail is "Nothing" or "The whole run once it finishes", check that a visitor held at it sees a "Check again" button, and that pressing it after the time has come carries their answers and completion times forward and moves them past the Wait step.
181
195
  - After setting `EasyFlow.data_source`, check that a Read data step on the canvas offers the object's `reads` and a Write data step offers its `writes`. Publish a flow set to save each step, connect each step's `passed` and `failed` connections, and check a run follows `passed` when `carry_out` answers and `failed` when it raises.
182
196
  - After setting `EasyFlow.file_store`, publish a flow with a File upload step whose "What this keeps of a run" detail is "Every answer as it is given", upload a file as a visitor, and check that the completion page shows the name the store gives it.
@@ -9,6 +9,7 @@ install:
9
9
  - EasyFlow.file_store
10
10
  - EasyFlow.picture_store
11
11
  - EasyFlow.data_source
12
+ - EasyFlow.on_held
12
13
  - EasyFlow.check
13
14
  - /manage/flows
14
15
 
@@ -17,6 +18,7 @@ develop:
17
18
  - EasyFlow.step
18
19
  - labels_answer_by
19
20
  - outputs_named_by
21
+ - holds_until
20
22
  - EasyFlow::Inputs
21
23
  - host.allowed_answers=
22
24
  - EasyFlow::FlowsController
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.54.0
4
+ version: 0.56.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tylercschneider