dwf 0.1.9 → 0.1.13
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/.github/workflows/build_gem.yaml +0 -4
- data/.github/workflows/test.yaml +5 -1
- data/.gitignore +1 -0
- data/CHANGELOG.md +127 -0
- data/README.md +150 -36
- data/dwf.gemspec +9 -6
- data/lib/dwf/callback.rb +16 -14
- data/lib/dwf/client.rb +82 -9
- data/lib/dwf/concerns/checkable.rb +29 -0
- data/lib/dwf/errors.rb +3 -0
- data/lib/dwf/item.rb +55 -39
- data/lib/dwf/utils.rb +6 -0
- data/lib/dwf/version.rb +1 -1
- data/lib/dwf/workflow.rb +154 -35
- data/spec/dwf/client_spec.rb +109 -18
- data/spec/dwf/item_spec.rb +86 -33
- data/spec/dwf/utils_spec.rb +9 -0
- data/spec/dwf/workflow_spec.rb +376 -0
- data/spec/spec_helper.rb +3 -0
- metadata +42 -11
data/spec/dwf/item_spec.rb
CHANGED
@@ -20,7 +20,8 @@ describe Dwf::Item, item: true do
|
|
20
20
|
klass: 'Dwf::Item',
|
21
21
|
started_at: started_at,
|
22
22
|
finished_at: finished_at,
|
23
|
-
callback_type: Dwf::Workflow::BUILD_IN
|
23
|
+
callback_type: Dwf::Workflow::BUILD_IN,
|
24
|
+
payloads: nil
|
24
25
|
}
|
25
26
|
end
|
26
27
|
let!(:item) { described_class.new(options) }
|
@@ -89,7 +90,7 @@ describe Dwf::Item, item: true do
|
|
89
90
|
before do
|
90
91
|
allow(Dwf::Client).to receive(:new).and_return client_double
|
91
92
|
allow(client_double)
|
92
|
-
.to receive(:
|
93
|
+
.to receive(:find_node).and_return a_item
|
93
94
|
end
|
94
95
|
|
95
96
|
context 'parent jobs already finished' do
|
@@ -98,8 +99,8 @@ describe Dwf::Item, item: true do
|
|
98
99
|
it do
|
99
100
|
expect(item.parents_succeeded?).to be_truthy
|
100
101
|
expect(client_double)
|
101
|
-
.to have_received(:
|
102
|
-
.with(
|
102
|
+
.to have_received(:find_node)
|
103
|
+
.with(incoming.first, workflow_id)
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
@@ -109,8 +110,8 @@ describe Dwf::Item, item: true do
|
|
109
110
|
it do
|
110
111
|
expect(item.parents_succeeded?).to be_falsy
|
111
112
|
expect(client_double)
|
112
|
-
.to have_received(:
|
113
|
-
.with(
|
113
|
+
.to have_received(:find_node)
|
114
|
+
.with(incoming.first, workflow_id)
|
114
115
|
end
|
115
116
|
end
|
116
117
|
end
|
@@ -148,37 +149,51 @@ describe Dwf::Item, item: true do
|
|
148
149
|
end
|
149
150
|
|
150
151
|
describe '#enqueue_outgoing_jobs' do
|
151
|
-
let(:outgoing) { ["A|#{SecureRandom.uuid}"] }
|
152
152
|
let(:client_double) do
|
153
153
|
double(
|
154
|
-
|
154
|
+
find_node: nil,
|
155
155
|
check_or_lock: nil,
|
156
|
-
release_lock: nil
|
156
|
+
release_lock: nil,
|
157
|
+
build_workflow_id: SecureRandom.uuid
|
157
158
|
)
|
158
159
|
end
|
159
|
-
let(:a_item) do
|
160
|
-
described_class.new(
|
161
|
-
workflow_id: SecureRandom.uuid,
|
162
|
-
id: SecureRandom.uuid,
|
163
|
-
started_at: started_at
|
164
|
-
)
|
165
|
-
end
|
166
|
-
before do
|
167
|
-
allow(Dwf::Client).to receive(:new).and_return client_double
|
168
|
-
allow(a_item).to receive(:persist_and_perform_async!)
|
169
|
-
allow(client_double)
|
170
|
-
.to receive(:find_job).and_return a_item
|
171
|
-
item.enqueue_outgoing_jobs
|
172
|
-
end
|
173
160
|
|
174
|
-
context '
|
175
|
-
let(:
|
176
|
-
|
161
|
+
context 'when item is not a leaf' do
|
162
|
+
let(:outgoing) { ["A|#{SecureRandom.uuid}"] }
|
163
|
+
let(:a_item) do
|
164
|
+
described_class.new(
|
165
|
+
workflow_id: SecureRandom.uuid,
|
166
|
+
id: SecureRandom.uuid,
|
167
|
+
started_at: started_at
|
168
|
+
)
|
169
|
+
end
|
170
|
+
before do
|
171
|
+
allow(Dwf::Client).to receive(:new).and_return client_double
|
172
|
+
allow(a_item).to receive(:persist_and_perform_async!)
|
173
|
+
allow(client_double)
|
174
|
+
.to receive(:find_node).and_return a_item
|
175
|
+
item.enqueue_outgoing_jobs
|
176
|
+
end
|
177
|
+
|
178
|
+
it do
|
179
|
+
expect(client_double).to have_received(:check_or_lock) do |&block|
|
180
|
+
expect(block).to be_kind_of Proc
|
181
|
+
end
|
182
|
+
end
|
177
183
|
end
|
178
184
|
|
179
|
-
context '
|
180
|
-
let(:
|
181
|
-
|
185
|
+
context 'when item is a leaf' do
|
186
|
+
let(:leaf) { true }
|
187
|
+
let(:workflow) { Dwf::Workflow.new }
|
188
|
+
before do
|
189
|
+
allow(Dwf::Client).to receive(:new).and_return client_double
|
190
|
+
allow(client_double).to receive(:find_workflow).and_return workflow
|
191
|
+
allow(workflow).to receive(:enqueue_outgoing_jobs)
|
192
|
+
item.enqueue_outgoing_jobs
|
193
|
+
end
|
194
|
+
|
195
|
+
let(:started_at) { nil }
|
196
|
+
it { expect(workflow).to have_received(:enqueue_outgoing_jobs) }
|
182
197
|
end
|
183
198
|
end
|
184
199
|
|
@@ -189,8 +204,9 @@ describe Dwf::Item, item: true do
|
|
189
204
|
end
|
190
205
|
|
191
206
|
describe '#payloads' do
|
192
|
-
let(:incoming) { ["
|
193
|
-
let(:client_double) { double(find_job: nil) }
|
207
|
+
let(:incoming) { ["Dwf::Item|#{SecureRandom.uuid}", "Dwf::Workflow|#{workflow_id}"] }
|
208
|
+
let(:client_double) { double(find_job: nil, build_workflow_id: workflow_id) }
|
209
|
+
let(:workflow) { Dwf::Workflow.new }
|
194
210
|
let!(:a_item) do
|
195
211
|
described_class.new(
|
196
212
|
workflow_id: SecureRandom.uuid,
|
@@ -203,7 +219,11 @@ describe Dwf::Item, item: true do
|
|
203
219
|
before do
|
204
220
|
allow(Dwf::Client).to receive(:new).and_return client_double
|
205
221
|
allow(client_double)
|
206
|
-
.to receive(:
|
222
|
+
.to receive(:find_node)
|
223
|
+
.with(incoming.first, workflow_id).and_return a_item
|
224
|
+
allow(client_double)
|
225
|
+
.to receive(:find_node)
|
226
|
+
.with(incoming.last, workflow_id).and_return workflow
|
207
227
|
end
|
208
228
|
|
209
229
|
it do
|
@@ -212,9 +232,42 @@ describe Dwf::Item, item: true do
|
|
212
232
|
class: a_item.class.name,
|
213
233
|
id: a_item.name,
|
214
234
|
output: 1
|
235
|
+
},
|
236
|
+
{
|
237
|
+
class: workflow.class.name,
|
238
|
+
id: workflow.name,
|
239
|
+
output: []
|
215
240
|
}
|
216
241
|
]
|
217
|
-
expect(item.payloads).to
|
242
|
+
expect(item.payloads).to match_array expected_payload
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#start_batch!' do
|
247
|
+
let(:callback_double) { double(start: nil) }
|
248
|
+
let(:client_double) { double(persist_job: nil) }
|
249
|
+
|
250
|
+
before do
|
251
|
+
allow(Dwf::Client).to receive(:new).and_return client_double
|
252
|
+
allow(Dwf::Callback).to receive(:new).and_return callback_double
|
253
|
+
item.start_batch!
|
254
|
+
end
|
255
|
+
|
256
|
+
it do
|
257
|
+
expect(callback_double).to have_received(:start).with(item)
|
258
|
+
expect(item.enqueued_at).not_to be_nil
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
describe '#leaf?' do
|
263
|
+
context 'when item has outgoing item' do
|
264
|
+
let(:outgoing) { ["Dwf::Item|#{SecureRandom.uuid}"] }
|
265
|
+
it { expect(item.leaf?).to be_falsy }
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'when item does not have outgoing item' do
|
269
|
+
let(:outgoing) { [] }
|
270
|
+
it { expect(item.leaf?).to be_truthy }
|
218
271
|
end
|
219
272
|
end
|
220
273
|
end
|
data/spec/dwf/utils_spec.rb
CHANGED
@@ -20,4 +20,13 @@ describe Dwf::Utils, utils: true do
|
|
20
20
|
|
21
21
|
it { expect(described_class.symbolize_keys(hash)).to eq expected }
|
22
22
|
end
|
23
|
+
|
24
|
+
describe "#workflow_name?" do
|
25
|
+
FirstWorkflow = Class.new(Dwf::Workflow)
|
26
|
+
FirstJob = Class.new(Dwf::Item)
|
27
|
+
|
28
|
+
it { expect(described_class.workflow_name?(Dwf::Workflow.name)).to be_truthy }
|
29
|
+
it { expect(described_class.workflow_name?(FirstWorkflow.name)).to be_truthy }
|
30
|
+
it { expect(described_class.workflow_name?(FirstJob.name)).to be_falsy }
|
31
|
+
end
|
23
32
|
end
|
@@ -0,0 +1,376 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'mock_redis'
|
5
|
+
AItem = Class.new(Dwf::Item)
|
6
|
+
BItem = Class.new(Dwf::Item)
|
7
|
+
CItem = Class.new(Dwf::Item)
|
8
|
+
SWorkflow = Class.new(Dwf::Workflow)
|
9
|
+
|
10
|
+
describe Dwf::Workflow, workflow: true do
|
11
|
+
let(:workflow_id) { SecureRandom.uuid }
|
12
|
+
let(:item_id) { SecureRandom.uuid }
|
13
|
+
let(:item) { nil }
|
14
|
+
let(:client) do
|
15
|
+
double(
|
16
|
+
persist_workflow: nil,
|
17
|
+
persist_job: nil,
|
18
|
+
build_workflow_id: workflow_id,
|
19
|
+
build_job_id: item_id,
|
20
|
+
find_workflow: nil,
|
21
|
+
find_node: item,
|
22
|
+
check_or_lock: nil,
|
23
|
+
release_lock: nil
|
24
|
+
)
|
25
|
+
end
|
26
|
+
before do
|
27
|
+
allow(Dwf::Client).to receive(:new).and_return client
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#create' do
|
31
|
+
it do
|
32
|
+
workflow = described_class.create
|
33
|
+
expect(client).to have_received(:persist_workflow)
|
34
|
+
.with(an_instance_of(described_class))
|
35
|
+
expect(workflow.id).to eq workflow_id
|
36
|
+
expect(workflow.persisted).to be_truthy
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#find' do
|
41
|
+
before { Dwf::Workflow.find(workflow_id) }
|
42
|
+
|
43
|
+
it { expect(client).to have_received(:find_workflow).with(workflow_id) }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#persist!' do
|
47
|
+
let(:workflow) { described_class.new }
|
48
|
+
let(:job) do
|
49
|
+
Dwf::Item.new(
|
50
|
+
worflow_id: workflow_id,
|
51
|
+
id: item_id
|
52
|
+
)
|
53
|
+
end
|
54
|
+
before do
|
55
|
+
workflow.jobs << job
|
56
|
+
workflow.persist!
|
57
|
+
end
|
58
|
+
|
59
|
+
it do
|
60
|
+
expect(client).to have_received(:persist_workflow)
|
61
|
+
.with(an_instance_of(described_class))
|
62
|
+
expect(client).to have_received(:persist_job).with(job)
|
63
|
+
expect(workflow.id).to eq workflow_id
|
64
|
+
expect(workflow.persisted).to be_truthy
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#start' do
|
69
|
+
let(:workflow) { described_class.new }
|
70
|
+
let(:job) do
|
71
|
+
Dwf::Item.new(
|
72
|
+
worflow_id: workflow_id,
|
73
|
+
id: item_id
|
74
|
+
)
|
75
|
+
end
|
76
|
+
before do
|
77
|
+
workflow.jobs << job
|
78
|
+
workflow.persist!
|
79
|
+
end
|
80
|
+
|
81
|
+
it do
|
82
|
+
expect(client).to have_received(:persist_workflow)
|
83
|
+
.with(an_instance_of(described_class))
|
84
|
+
expect(client).to have_received(:persist_job).with(job)
|
85
|
+
expect(workflow.id).to eq workflow_id
|
86
|
+
expect(workflow.persisted).to be_truthy
|
87
|
+
expect(workflow.stopped).to be_falsy
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe '#run' do
|
92
|
+
let!(:workflow) { described_class.new }
|
93
|
+
|
94
|
+
before do
|
95
|
+
workflow.run AItem, after: BItem, before: CItem
|
96
|
+
workflow.run SWorkflow, after: AItem
|
97
|
+
end
|
98
|
+
|
99
|
+
it do
|
100
|
+
expect(workflow.jobs).not_to be_empty
|
101
|
+
expected = [
|
102
|
+
{
|
103
|
+
from: BItem.to_s,
|
104
|
+
to: "AItem|#{item_id}"
|
105
|
+
},
|
106
|
+
{
|
107
|
+
from: "AItem|#{item_id}",
|
108
|
+
to: CItem.to_s
|
109
|
+
},
|
110
|
+
{
|
111
|
+
from: AItem.to_s,
|
112
|
+
to: "SWorkflow|#{workflow_id}"
|
113
|
+
}
|
114
|
+
]
|
115
|
+
expect(workflow.dependencies).to match_array expected
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#find_job' do
|
120
|
+
let!(:workflow) { described_class.new }
|
121
|
+
before do
|
122
|
+
workflow.jobs = [
|
123
|
+
AItem.new,
|
124
|
+
BItem.new(id: item_id),
|
125
|
+
CItem.new
|
126
|
+
]
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'searches by klass' do
|
130
|
+
job = workflow.find_job('AItem')
|
131
|
+
expect(job).to be_kind_of AItem
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'searches by name' do
|
135
|
+
job = workflow.find_job("BItem|#{item_id}")
|
136
|
+
expect(job).to be_kind_of BItem
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '#setup' do
|
141
|
+
let!(:workflow) { described_class.new }
|
142
|
+
before do
|
143
|
+
workflow.run AItem
|
144
|
+
workflow.run BItem, after: AItem
|
145
|
+
workflow.run SWorkflow, after: BItem
|
146
|
+
workflow.run CItem, after: SWorkflow
|
147
|
+
|
148
|
+
workflow.send(:setup)
|
149
|
+
end
|
150
|
+
|
151
|
+
it do
|
152
|
+
job_a = workflow.find_job("AItem")
|
153
|
+
|
154
|
+
expect(job_a.incoming).to be_empty
|
155
|
+
expect(job_a.outgoing).to eq ["BItem|#{item_id}"]
|
156
|
+
|
157
|
+
job_b = workflow.find_job('BItem')
|
158
|
+
|
159
|
+
expect(job_b.incoming).to eq ["AItem|#{item_id}"]
|
160
|
+
expect(job_b.outgoing).to eq ["SWorkflow|#{workflow_id}"]
|
161
|
+
|
162
|
+
job_c = workflow.find_job('CItem')
|
163
|
+
|
164
|
+
expect(job_c.incoming).to eq ["SWorkflow|#{workflow_id}"]
|
165
|
+
expect(job_c.outgoing).to be_empty
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe '#callback_type' do
|
170
|
+
let!(:workflow) { described_class.new }
|
171
|
+
|
172
|
+
it do
|
173
|
+
expect(workflow.callback_type).to eq described_class::BUILD_IN
|
174
|
+
workflow.callback_type = described_class::SK_BATCH
|
175
|
+
expect(workflow.callback_type).to eq described_class::SK_BATCH
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe '#reload' do
|
180
|
+
let!(:workflow) do
|
181
|
+
flow = described_class.new
|
182
|
+
flow.id = workflow_id
|
183
|
+
flow
|
184
|
+
end
|
185
|
+
|
186
|
+
before do
|
187
|
+
allow(client).to receive(:find_workflow).and_return workflow
|
188
|
+
workflow.reload
|
189
|
+
end
|
190
|
+
|
191
|
+
it { expect(client).to have_received(:find_workflow).with(workflow_id) }
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#parents_succeeded?' do
|
195
|
+
let(:incoming) { ["A|#{SecureRandom.uuid}"] }
|
196
|
+
let!(:workflow) do
|
197
|
+
flow = described_class.new
|
198
|
+
flow.parent_id = SecureRandom.uuid
|
199
|
+
flow.incoming = incoming
|
200
|
+
flow
|
201
|
+
end
|
202
|
+
let(:item) do
|
203
|
+
Dwf::Item.new(
|
204
|
+
workflow_id: SecureRandom.uuid,
|
205
|
+
id: SecureRandom.uuid,
|
206
|
+
finished_at: finished_at
|
207
|
+
)
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'parent jobs already finished' do
|
211
|
+
let(:finished_at) { Time.now.to_i }
|
212
|
+
|
213
|
+
it do
|
214
|
+
expect(workflow.parents_succeeded?).to be_truthy
|
215
|
+
expect(client).to have_received(:find_node)
|
216
|
+
.with(incoming.first, workflow.parent_id)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'parent jobs havent finished yet' do
|
221
|
+
let(:finished_at) { nil }
|
222
|
+
|
223
|
+
it do
|
224
|
+
expect(workflow.parents_succeeded?).to be_falsy
|
225
|
+
expect(client)
|
226
|
+
.to have_received(:find_node)
|
227
|
+
.with(incoming.first, workflow.parent_id)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#sub_workflow?' do
|
233
|
+
let!(:workflow) { described_class.new }
|
234
|
+
let!(:sub_workflow) do
|
235
|
+
flow = described_class.new
|
236
|
+
flow.parent_id = workflow.id
|
237
|
+
flow
|
238
|
+
end
|
239
|
+
|
240
|
+
specify do
|
241
|
+
expect(workflow.sub_workflow?).to be_falsy
|
242
|
+
expect(sub_workflow.sub_workflow?).to be_truthy
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe '#payloads' do
|
247
|
+
let!(:item) do
|
248
|
+
Dwf::Item.new(
|
249
|
+
workflow_id: SecureRandom.uuid,
|
250
|
+
id: SecureRandom.uuid,
|
251
|
+
output_payload: 1
|
252
|
+
)
|
253
|
+
end
|
254
|
+
let(:workflow) { described_class.new }
|
255
|
+
|
256
|
+
context 'when workflow is main flow' do
|
257
|
+
it { expect(workflow.payloads).to be_nil }
|
258
|
+
end
|
259
|
+
|
260
|
+
context 'when workflow is sub flow' do
|
261
|
+
before do
|
262
|
+
workflow.incoming = incoming
|
263
|
+
workflow.parent_id = SecureRandom.uuid
|
264
|
+
end
|
265
|
+
|
266
|
+
context 'when incoming blank' do
|
267
|
+
let(:incoming) { [] }
|
268
|
+
it { expect(workflow.payloads).to be_nil }
|
269
|
+
end
|
270
|
+
|
271
|
+
context 'when incoming present' do
|
272
|
+
let(:incoming) { ["Dwf::Item|#{SecureRandom.uuid}", "Dwf::Workflow|#{workflow_id}"] }
|
273
|
+
it do
|
274
|
+
expected_payload = [
|
275
|
+
{
|
276
|
+
class: item.class.name,
|
277
|
+
id: item.name,
|
278
|
+
output: 1
|
279
|
+
}
|
280
|
+
]
|
281
|
+
expect(workflow.payloads).to eq expected_payload
|
282
|
+
expect(client).to have_received(:find_node).with(incoming.first, workflow.parent_id)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe '#left?' do
|
289
|
+
let(:workflow) { described_class.new }
|
290
|
+
before { workflow.outgoing = outgoing }
|
291
|
+
|
292
|
+
context 'when item has outgoing item' do
|
293
|
+
let(:outgoing) { ["Dwf::Item|#{SecureRandom.uuid}"] }
|
294
|
+
it { expect(workflow.leaf?).to be_falsy }
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'when item does not have outgoing item' do
|
298
|
+
let(:outgoing) { [] }
|
299
|
+
it { expect(workflow.leaf?).to be_truthy }
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe '#leaf_nodes' do
|
304
|
+
let!(:workflow) { described_class.new }
|
305
|
+
before do
|
306
|
+
workflow.run AItem
|
307
|
+
workflow.run BItem, after: AItem
|
308
|
+
workflow.run SWorkflow, after: BItem
|
309
|
+
workflow.run CItem, after: SWorkflow
|
310
|
+
|
311
|
+
workflow.send(:setup)
|
312
|
+
end
|
313
|
+
|
314
|
+
specify do
|
315
|
+
expect(workflow.leaf_nodes.count).to eq 1
|
316
|
+
expect(workflow.leaf_nodes.first).to be_kind_of CItem
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
describe '#output_payloads' do
|
321
|
+
let!(:workflow) { described_class.new }
|
322
|
+
before do
|
323
|
+
allow_any_instance_of(CItem).to receive(:output_payload).and_return 1
|
324
|
+
workflow.run AItem
|
325
|
+
workflow.run BItem, after: AItem
|
326
|
+
workflow.run SWorkflow, after: BItem
|
327
|
+
workflow.run CItem, after: SWorkflow
|
328
|
+
|
329
|
+
workflow.send(:setup)
|
330
|
+
end
|
331
|
+
|
332
|
+
it { expect(workflow.output_payload).to eq [1] }
|
333
|
+
end
|
334
|
+
|
335
|
+
describe '#callback_type=' do
|
336
|
+
let!(:workflow) { described_class.new }
|
337
|
+
before do
|
338
|
+
workflow.run AItem
|
339
|
+
workflow.run BItem, after: AItem
|
340
|
+
|
341
|
+
workflow.send(:setup)
|
342
|
+
workflow.callback_type = described_class::SK_BATCH
|
343
|
+
end
|
344
|
+
|
345
|
+
specify do
|
346
|
+
expect(workflow.callback_type).to eq described_class::SK_BATCH
|
347
|
+
job_callback_types = workflow.jobs.map(&:callback_type).uniq
|
348
|
+
expect(job_callback_types).to eq [described_class::SK_BATCH]
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe '#enqueue_outgoing_jobs' do
|
353
|
+
let(:outgoing) { ["A|#{SecureRandom.uuid}"] }
|
354
|
+
let!(:workflow) do
|
355
|
+
flow = described_class.new
|
356
|
+
flow.parent_id = SecureRandom.uuid
|
357
|
+
flow.outgoing = outgoing
|
358
|
+
flow
|
359
|
+
end
|
360
|
+
let(:item) do
|
361
|
+
Dwf::Item.new(
|
362
|
+
workflow_id: SecureRandom.uuid,
|
363
|
+
id: SecureRandom.uuid
|
364
|
+
)
|
365
|
+
end
|
366
|
+
before do
|
367
|
+
workflow.enqueue_outgoing_jobs
|
368
|
+
end
|
369
|
+
|
370
|
+
it do
|
371
|
+
expect(client).to have_received(:check_or_lock) do |&block|
|
372
|
+
expect(block).to be_kind_of Proc
|
373
|
+
end
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'dwf'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.start
|
2
5
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
6
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
7
|
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dwf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dthtien
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 11.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mock_redis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.27.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.27.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: redis
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,33 +53,33 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 4.2.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: redis-mutex
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
61
|
+
version: 4.0.2
|
62
|
+
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 4.0.2
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: '3.2'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: '3.2'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: sidekiq
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,20 @@ dependencies:
|
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: 6.2.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
83
111
|
description: Workflow
|
84
112
|
email:
|
85
113
|
- tiendt2311@gmail.com
|
@@ -100,7 +128,9 @@ files:
|
|
100
128
|
- lib/dwf.rb
|
101
129
|
- lib/dwf/callback.rb
|
102
130
|
- lib/dwf/client.rb
|
131
|
+
- lib/dwf/concerns/checkable.rb
|
103
132
|
- lib/dwf/configuration.rb
|
133
|
+
- lib/dwf/errors.rb
|
104
134
|
- lib/dwf/item.rb
|
105
135
|
- lib/dwf/utils.rb
|
106
136
|
- lib/dwf/version.rb
|
@@ -111,6 +141,7 @@ files:
|
|
111
141
|
- spec/dwf/item_spec.rb
|
112
142
|
- spec/dwf/utils_spec.rb
|
113
143
|
- spec/dwf/worker_spec.rb
|
144
|
+
- spec/dwf/workflow_spec.rb
|
114
145
|
- spec/spec_helper.rb
|
115
146
|
homepage: https://github.com/dthtien/wf
|
116
147
|
licenses:
|
@@ -134,12 +165,12 @@ requirements: []
|
|
134
165
|
rubygems_version: 3.2.3
|
135
166
|
signing_key:
|
136
167
|
specification_version: 4
|
137
|
-
summary:
|
138
|
-
DSL purpose
|
168
|
+
summary: Distributed workflow runner following Gush interface using Sidekiq and Redis
|
139
169
|
test_files:
|
140
170
|
- spec/dwf/client_spec.rb
|
141
171
|
- spec/dwf/configuration_spec.rb
|
142
172
|
- spec/dwf/item_spec.rb
|
143
173
|
- spec/dwf/utils_spec.rb
|
144
174
|
- spec/dwf/worker_spec.rb
|
175
|
+
- spec/dwf/workflow_spec.rb
|
145
176
|
- spec/spec_helper.rb
|