ductwork 0.25.0 → 0.26.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 +4 -4
- data/CHANGELOG-PRO.md +12 -0
- data/CHANGELOG.md +4 -0
- data/lib/ductwork/dsl/branch_builder.rb +40 -0
- data/lib/ductwork/dsl/definition_builder.rb +77 -1
- data/lib/ductwork/models/pipeline.rb +20 -1
- data/lib/ductwork/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ad0ce6f40af82ff2fcc08abb65083e32fdee666be43646a9f53f59033da85fa6
|
|
4
|
+
data.tar.gz: 7ba3f5a80167323fff58ae89b82fbfa44d10e4d20d6f6046436906250f1d9715
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34b29a0aaacc4994fadd9542c2d38696c15b88caaa6660f36d0b2cdac82aca27b818e7173ef633e03d2deea0fd162a24db41a7090feab2ff8c68d1fc6b8bcec3
|
|
7
|
+
data.tar.gz: 68bf238bdc9bdf4528cbbd5ba2554525d849d6008e5a7a6c5c0e35c96cf2896c04c2a8900ba29b69188b34f6ea1d30692dd25762b174c7b8bd7ee8afa146d9c1
|
data/CHANGELOG-PRO.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Ductwork Pro Changelog
|
|
2
2
|
|
|
3
|
+
## [0.7.0]
|
|
4
|
+
|
|
5
|
+
- feat: allow for passing an argument when resuming a pipeline - this will replace passing the previous step's output payload as the input arguments to the next step
|
|
6
|
+
|
|
7
|
+
## [0.6.0]
|
|
8
|
+
|
|
9
|
+
- feat: introduce `dampen` transition - this is the first iteration of the human-in-the-loop feature
|
|
10
|
+
- fix: bump `ductwork` dependency to v0.25.0
|
|
11
|
+
- fix: bump `ductwork` dependency to v0.24.0
|
|
12
|
+
- fix: bump `ductwork` dependency to v0.23.0 and set pipeline klass when creating availabilities
|
|
13
|
+
- feat: add optional `to` keyword argument to `chain` transition - this makes the DSL a bit more aligned
|
|
14
|
+
|
|
3
15
|
## [0.5.0]
|
|
4
16
|
|
|
5
17
|
- feat: enqueue jobs in batches when expanding and support starting delays
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Ductwork Changelog
|
|
2
2
|
|
|
3
|
+
## [0.26.0]
|
|
4
|
+
|
|
5
|
+
- feat: add `divert` and complementary `converge` transitions - this is essentially a conditional/case statement transition for pipelines including it's "fan-in" method
|
|
6
|
+
|
|
3
7
|
## [0.25.0]
|
|
4
8
|
|
|
5
9
|
- chore: align "dampen" naming and remove "pause" naming
|
|
@@ -43,6 +43,31 @@ module Ductwork
|
|
|
43
43
|
self
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
def divert(to:)
|
|
47
|
+
to_map = {}
|
|
48
|
+
next_nodes = []
|
|
49
|
+
to.each do |key, klass|
|
|
50
|
+
node = node_name(klass)
|
|
51
|
+
definition[:edges][node] ||= { klass: klass.name }
|
|
52
|
+
to_map[key.to_s] = node
|
|
53
|
+
next_nodes << node
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
definition[:edges][last_node][:to] = to_map
|
|
57
|
+
definition[:edges][last_node][:type] = :divert
|
|
58
|
+
definition[:nodes].push(*next_nodes)
|
|
59
|
+
|
|
60
|
+
if block_given?
|
|
61
|
+
sub_branches = next_nodes.map do |last_node|
|
|
62
|
+
Ductwork::DSL::BranchBuilder.new(last_node:, definition:)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
yield sub_branches
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
self
|
|
69
|
+
end
|
|
70
|
+
|
|
46
71
|
def combine(*branch_builders, into:)
|
|
47
72
|
next_klass_name = node_name(into)
|
|
48
73
|
definition[:edges][last_node][:to] = [next_klass_name]
|
|
@@ -58,6 +83,21 @@ module Ductwork
|
|
|
58
83
|
self
|
|
59
84
|
end
|
|
60
85
|
|
|
86
|
+
def converge(*branch_builders, into:)
|
|
87
|
+
next_klass_name = node_name(into)
|
|
88
|
+
definition[:edges][last_node][:to] = [next_klass_name]
|
|
89
|
+
definition[:edges][last_node][:type] = :converge
|
|
90
|
+
|
|
91
|
+
branch_builders.each do |branch|
|
|
92
|
+
definition[:edges][branch.last_node][:to] = [next_klass_name]
|
|
93
|
+
definition[:edges][branch.last_node][:type] = :converge
|
|
94
|
+
end
|
|
95
|
+
definition[:nodes].push(next_klass_name)
|
|
96
|
+
definition[:edges][next_klass_name] ||= { klass: into.name }
|
|
97
|
+
|
|
98
|
+
self
|
|
99
|
+
end
|
|
100
|
+
|
|
61
101
|
def expand(to:)
|
|
62
102
|
next_klass_name = node_name(to)
|
|
63
103
|
definition[:edges][last_node][:to] = [next_klass_name]
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module Ductwork
|
|
4
4
|
module DSL
|
|
5
|
-
class DefinitionBuilder
|
|
5
|
+
class DefinitionBuilder # rubocop:todo Metrics/ClassLength
|
|
6
6
|
class StartError < StandardError; end
|
|
7
7
|
class CollapseError < StandardError; end
|
|
8
8
|
class CombineError < StandardError; end
|
|
9
|
+
class DivertError < StandardError; end
|
|
10
|
+
class ConvergeError < StandardError; end
|
|
9
11
|
|
|
10
12
|
def initialize
|
|
11
13
|
@definition = {
|
|
@@ -112,6 +114,66 @@ module Ductwork
|
|
|
112
114
|
self
|
|
113
115
|
end
|
|
114
116
|
|
|
117
|
+
def divert(to:) # rubocop:todo Metrics/AbcSize
|
|
118
|
+
validate_classes!(to.values)
|
|
119
|
+
validate_definition_started!(action: "diverting chain")
|
|
120
|
+
validate_fallback_step!(to.keys)
|
|
121
|
+
|
|
122
|
+
to_map = {}
|
|
123
|
+
to_nodes = []
|
|
124
|
+
to.each do |key, klass|
|
|
125
|
+
node = node_name(klass)
|
|
126
|
+
definition[:edges][node] ||= { klass: klass.name }
|
|
127
|
+
to_map[key.to_s] = node
|
|
128
|
+
to_nodes << node
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
last_nodes.each do |last_node|
|
|
132
|
+
definition[:edges][last_node][:to] = to_map
|
|
133
|
+
definition[:edges][last_node][:type] = :divert
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
@last_nodes = to_nodes
|
|
137
|
+
|
|
138
|
+
definition[:nodes].push(*to_nodes)
|
|
139
|
+
divergences.push(:divert)
|
|
140
|
+
|
|
141
|
+
if block_given?
|
|
142
|
+
branches = last_nodes.map do |last_node|
|
|
143
|
+
Ductwork::DSL::BranchBuilder
|
|
144
|
+
.new(last_node:, definition:)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
yield branches
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
self
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def converge(into:) # rubocop:todo Metrics/AbcSize
|
|
154
|
+
validate_classes!(into)
|
|
155
|
+
validate_definition_started!(action: "converging steps")
|
|
156
|
+
validate_can_converge!
|
|
157
|
+
|
|
158
|
+
divergences.pop
|
|
159
|
+
|
|
160
|
+
into_node = node_name(into)
|
|
161
|
+
definition[:edges][into_node] ||= { klass: into.name }
|
|
162
|
+
last_nodes = definition[:nodes].reverse.select do |node|
|
|
163
|
+
definition.dig(:edges, node, :to).blank?
|
|
164
|
+
end
|
|
165
|
+
last_nodes.each do |last_node|
|
|
166
|
+
definition[:edges][last_node][:to] = [into_node]
|
|
167
|
+
definition[:edges][last_node][:type] = :converge
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
@last_nodes = Array(into_node)
|
|
171
|
+
|
|
172
|
+
definition[:nodes].push(into_node)
|
|
173
|
+
|
|
174
|
+
self
|
|
175
|
+
end
|
|
176
|
+
|
|
115
177
|
def on_halt(klass)
|
|
116
178
|
validate_classes!(klass)
|
|
117
179
|
|
|
@@ -176,6 +238,20 @@ module Ductwork
|
|
|
176
238
|
end
|
|
177
239
|
end
|
|
178
240
|
|
|
241
|
+
def validate_can_converge!
|
|
242
|
+
if divergences.empty?
|
|
243
|
+
raise ConvergeError, "Must divert pipeline definition before converging steps"
|
|
244
|
+
elsif divergences[-1] != :divert
|
|
245
|
+
raise ConvergeError, "Ambiguous converge on most recently divided/expanded definition"
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def validate_fallback_step!(keys)
|
|
250
|
+
if keys.exclude?(:otherwise)
|
|
251
|
+
raise DivertError, "Must specify an `otherwise` branch"
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
179
255
|
def add_edge_to_last_nodes(*klasses, type:)
|
|
180
256
|
to_nodes = klasses.map do |klass|
|
|
181
257
|
node = node_name(klass)
|
|
@@ -196,7 +196,7 @@ module Ductwork
|
|
|
196
196
|
klass = edge[:klass]
|
|
197
197
|
|
|
198
198
|
steps.where(id: advancing_ids, klass: klass).find_each do |step|
|
|
199
|
-
if to_transition.in?(%w[chain divide])
|
|
199
|
+
if to_transition.in?(%w[chain divide divert converge])
|
|
200
200
|
advance_to_next_steps(step.id, edge)
|
|
201
201
|
elsif to_transition == "expand"
|
|
202
202
|
expand_to_next_steps(step.id, edge)
|
|
@@ -212,6 +212,25 @@ module Ductwork
|
|
|
212
212
|
end
|
|
213
213
|
|
|
214
214
|
def advance_to_next_steps(step_id, edge)
|
|
215
|
+
if edge[:type] == "divert"
|
|
216
|
+
advance_to_divert_step(step_id, edge)
|
|
217
|
+
else
|
|
218
|
+
advance_to_array_steps(step_id, edge)
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def advance_to_divert_step(step_id, edge)
|
|
223
|
+
input_arg = Ductwork::Job.find_by(step_id:).return_value
|
|
224
|
+
node = edge[:to][input_arg.to_s] || edge[:to]["otherwise"]
|
|
225
|
+
|
|
226
|
+
if node.nil?
|
|
227
|
+
halt!
|
|
228
|
+
else
|
|
229
|
+
create_step_and_enqueue_job(edge:, input_arg:, node:)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def advance_to_array_steps(step_id, edge)
|
|
215
234
|
too_many = edge[:to].tally.any? do |to_klass, count|
|
|
216
235
|
depth = Ductwork
|
|
217
236
|
.configuration
|
data/lib/ductwork/version.rb
CHANGED