dwf 0.1.8 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build_gem.yaml +0 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +95 -0
- data/README.md +122 -37
- data/dwf.gemspec +8 -6
- data/lib/dwf/callback.rb +13 -10
- data/lib/dwf/client.rb +76 -1
- data/lib/dwf/concerns/checkable.rb +29 -0
- data/lib/dwf/configuration.rb +1 -1
- data/lib/dwf/errors.rb +3 -0
- data/lib/dwf/item.rb +48 -34
- 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 +100 -3
- data/spec/dwf/item_spec.rb +90 -33
- data/spec/dwf/utils_spec.rb +9 -0
- data/spec/dwf/workflow_spec.rb +382 -0
- data/spec/spec_helper.rb +3 -0
- metadata +31 -14
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,55 @@ 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
|
+
context 'outgoing jobs ready to start' do
|
179
|
+
let(:started_at) { nil }
|
180
|
+
it { expect(a_item).to have_received(:persist_and_perform_async!) }
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'outgoing jobs havent ready to start' do
|
184
|
+
let(:started_at) { Time.now.to_i }
|
185
|
+
it { expect(a_item).not_to have_received(:persist_and_perform_async!) }
|
186
|
+
end
|
177
187
|
end
|
178
188
|
|
179
|
-
context '
|
180
|
-
let(:
|
181
|
-
|
189
|
+
context 'when item is a leaf' do
|
190
|
+
let(:leaf) { true }
|
191
|
+
let(:workflow) { Dwf::Workflow.new }
|
192
|
+
before do
|
193
|
+
allow(Dwf::Client).to receive(:new).and_return client_double
|
194
|
+
allow(client_double).to receive(:find_workflow).and_return workflow
|
195
|
+
allow(workflow).to receive(:enqueue_outgoing_jobs)
|
196
|
+
item.enqueue_outgoing_jobs
|
197
|
+
end
|
198
|
+
|
199
|
+
let(:started_at) { nil }
|
200
|
+
it { expect(workflow).to have_received(:enqueue_outgoing_jobs) }
|
182
201
|
end
|
183
202
|
end
|
184
203
|
|
@@ -189,8 +208,9 @@ describe Dwf::Item, item: true do
|
|
189
208
|
end
|
190
209
|
|
191
210
|
describe '#payloads' do
|
192
|
-
let(:incoming) { ["
|
193
|
-
let(:client_double) { double(find_job: nil) }
|
211
|
+
let(:incoming) { ["Dwf::Item|#{SecureRandom.uuid}", "Dwf::Workflow|#{workflow_id}"] }
|
212
|
+
let(:client_double) { double(find_job: nil, build_workflow_id: workflow_id) }
|
213
|
+
let(:workflow) { Dwf::Workflow.new }
|
194
214
|
let!(:a_item) do
|
195
215
|
described_class.new(
|
196
216
|
workflow_id: SecureRandom.uuid,
|
@@ -203,7 +223,11 @@ describe Dwf::Item, item: true do
|
|
203
223
|
before do
|
204
224
|
allow(Dwf::Client).to receive(:new).and_return client_double
|
205
225
|
allow(client_double)
|
206
|
-
.to receive(:
|
226
|
+
.to receive(:find_node)
|
227
|
+
.with(incoming.first, workflow_id).and_return a_item
|
228
|
+
allow(client_double)
|
229
|
+
.to receive(:find_node)
|
230
|
+
.with(incoming.last, workflow_id).and_return workflow
|
207
231
|
end
|
208
232
|
|
209
233
|
it do
|
@@ -212,9 +236,42 @@ describe Dwf::Item, item: true do
|
|
212
236
|
class: a_item.class.name,
|
213
237
|
id: a_item.name,
|
214
238
|
output: 1
|
239
|
+
},
|
240
|
+
{
|
241
|
+
class: workflow.class.name,
|
242
|
+
id: workflow.name,
|
243
|
+
output: []
|
215
244
|
}
|
216
245
|
]
|
217
|
-
expect(item.payloads).to
|
246
|
+
expect(item.payloads).to match_array expected_payload
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe '#start_batch!' do
|
251
|
+
let(:callback_double) { double(start: nil) }
|
252
|
+
let(:client_double) { double(persist_job: nil) }
|
253
|
+
|
254
|
+
before do
|
255
|
+
allow(Dwf::Client).to receive(:new).and_return client_double
|
256
|
+
allow(Dwf::Callback).to receive(:new).and_return callback_double
|
257
|
+
item.start_batch!
|
258
|
+
end
|
259
|
+
|
260
|
+
it do
|
261
|
+
expect(callback_double).to have_received(:start).with(item)
|
262
|
+
expect(item.enqueued_at).not_to be_nil
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe '#leaf?' do
|
267
|
+
context 'when item has outgoing item' do
|
268
|
+
let(:outgoing) { ["Dwf::Item|#{SecureRandom.uuid}"] }
|
269
|
+
it { expect(item.leaf?).to be_falsy }
|
270
|
+
end
|
271
|
+
|
272
|
+
context 'when item does not have outgoing item' do
|
273
|
+
let(:outgoing) { [] }
|
274
|
+
it { expect(item.leaf?).to be_truthy }
|
218
275
|
end
|
219
276
|
end
|
220
277
|
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,382 @@
|
|
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
|
+
started_at: started_at
|
365
|
+
)
|
366
|
+
end
|
367
|
+
before do
|
368
|
+
allow(item).to receive(:persist_and_perform_async!)
|
369
|
+
workflow.enqueue_outgoing_jobs
|
370
|
+
end
|
371
|
+
|
372
|
+
context 'outgoing jobs ready to start' do
|
373
|
+
let(:started_at) { nil }
|
374
|
+
it { expect(item).to have_received(:persist_and_perform_async!) }
|
375
|
+
end
|
376
|
+
|
377
|
+
context 'outgoing jobs havent ready to start' do
|
378
|
+
let(:started_at) { Time.now.to_i }
|
379
|
+
it { expect(item).not_to have_received(:persist_and_perform_async!) }
|
380
|
+
end
|
381
|
+
end
|
382
|
+
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.12
|
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-10 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
|
@@ -53,33 +67,33 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: sidekiq
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
62
|
-
type: :
|
75
|
+
version: 6.2.0
|
76
|
+
type: :runtime
|
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: 6.2.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
84
|
+
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: '0'
|
83
97
|
description: Workflow
|
84
98
|
email:
|
85
99
|
- tiendt2311@gmail.com
|
@@ -100,7 +114,9 @@ files:
|
|
100
114
|
- lib/dwf.rb
|
101
115
|
- lib/dwf/callback.rb
|
102
116
|
- lib/dwf/client.rb
|
117
|
+
- lib/dwf/concerns/checkable.rb
|
103
118
|
- lib/dwf/configuration.rb
|
119
|
+
- lib/dwf/errors.rb
|
104
120
|
- lib/dwf/item.rb
|
105
121
|
- lib/dwf/utils.rb
|
106
122
|
- lib/dwf/version.rb
|
@@ -111,6 +127,7 @@ files:
|
|
111
127
|
- spec/dwf/item_spec.rb
|
112
128
|
- spec/dwf/utils_spec.rb
|
113
129
|
- spec/dwf/worker_spec.rb
|
130
|
+
- spec/dwf/workflow_spec.rb
|
114
131
|
- spec/spec_helper.rb
|
115
132
|
homepage: https://github.com/dthtien/wf
|
116
133
|
licenses:
|
@@ -134,12 +151,12 @@ requirements: []
|
|
134
151
|
rubygems_version: 3.2.3
|
135
152
|
signing_key:
|
136
153
|
specification_version: 4
|
137
|
-
summary:
|
138
|
-
DSL purpose
|
154
|
+
summary: Distributed workflow runner following Gush interface using Sidekiq and Redis
|
139
155
|
test_files:
|
140
156
|
- spec/dwf/client_spec.rb
|
141
157
|
- spec/dwf/configuration_spec.rb
|
142
158
|
- spec/dwf/item_spec.rb
|
143
159
|
- spec/dwf/utils_spec.rb
|
144
160
|
- spec/dwf/worker_spec.rb
|
161
|
+
- spec/dwf/workflow_spec.rb
|
145
162
|
- spec/spec_helper.rb
|