canvas_sync 0.17.0.beta3 → 0.17.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canvas_sync/job_batches/batch.rb +10 -8
- data/lib/canvas_sync/job_batches/callback.rb +14 -10
- data/lib/canvas_sync/job_batches/chain_builder.rb +10 -0
- data/lib/canvas_sync/job_batches/status.rb +21 -1
- data/lib/canvas_sync/jobs/begin_sync_chain_job.rb +2 -1
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/job_batching/batch_spec.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2fac17ba7660bf59726320af878f6ca00b1d3dba48428677ee01dcaffdf210f
|
4
|
+
data.tar.gz: 05161fb24879704d5d68b7ae45a4a69c848db6c914666a307641de24081e0234
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1dbd39ffb4f0a58b90ecf9a36e493d360a88438aa93e7a40429e6a7f0004149c3e77a8da069c72df27f38d4657f769a5f6c309e4230a89db4d810d3afcac9f7
|
7
|
+
data.tar.gz: c4ae094ca61c7698aa95ab2378433ba1f84e1481ef6034fcce129e188c8fa309692cbc4e9a1c7607d38e77f292aad9128d59c5f115258c7f22c5b9d6b0cadd75
|
@@ -223,7 +223,7 @@ module CanvasSync
|
|
223
223
|
r.hincrby("BID-#{bid}", "pending", 0)
|
224
224
|
r.scard("BID-#{bid}-failed")
|
225
225
|
r.hincrby("BID-#{bid}", "children", 0)
|
226
|
-
r.scard("BID-#{bid}-complete")
|
226
|
+
r.scard("BID-#{bid}-batches-complete")
|
227
227
|
r.hget("BID-#{bid}", "parent_bid")
|
228
228
|
|
229
229
|
r.expire("BID-#{bid}-failed", BID_EXPIRE_TTL)
|
@@ -253,7 +253,7 @@ module CanvasSync
|
|
253
253
|
|
254
254
|
r.scard("BID-#{bid}-dead")
|
255
255
|
r.hincrby("BID-#{bid}", "children", 0)
|
256
|
-
r.scard("BID-#{bid}-complete")
|
256
|
+
r.scard("BID-#{bid}-batches-complete")
|
257
257
|
r.hget("BID-#{bid}", "parent_bid")
|
258
258
|
|
259
259
|
r.expire("BID-#{bid}-dead", BID_EXPIRE_TTL)
|
@@ -273,17 +273,18 @@ module CanvasSync
|
|
273
273
|
end
|
274
274
|
|
275
275
|
def process_successful_job(bid, jid)
|
276
|
-
failed, pending, children, complete, success, total, parent_bid = redis do |r|
|
276
|
+
_, failed, pending, children, complete, success, total, parent_bid = redis do |r|
|
277
277
|
r.multi do
|
278
|
+
r.srem("BID-#{bid}-failed", jid)
|
279
|
+
|
278
280
|
r.scard("BID-#{bid}-failed")
|
279
281
|
r.hincrby("BID-#{bid}", "pending", -1)
|
280
282
|
r.hincrby("BID-#{bid}", "children", 0)
|
281
|
-
r.scard("BID-#{bid}-complete")
|
282
|
-
r.scard("BID-#{bid}-success")
|
283
|
+
r.scard("BID-#{bid}-batches-complete")
|
284
|
+
r.scard("BID-#{bid}-batches-success")
|
283
285
|
r.hget("BID-#{bid}", "total")
|
284
286
|
r.hget("BID-#{bid}", "parent_bid")
|
285
287
|
|
286
|
-
r.srem("BID-#{bid}-failed", jid)
|
287
288
|
r.srem("BID-#{bid}-jids", jid)
|
288
289
|
r.expire("BID-#{bid}", BID_EXPIRE_TTL)
|
289
290
|
end
|
@@ -365,8 +366,9 @@ module CanvasSync
|
|
365
366
|
"BID-#{bid}-callbacks-success",
|
366
367
|
"BID-#{bid}-failed",
|
367
368
|
|
368
|
-
"BID-#{bid}-success",
|
369
|
-
"BID-#{bid}-complete",
|
369
|
+
"BID-#{bid}-batches-success",
|
370
|
+
"BID-#{bid}-batches-complete",
|
371
|
+
"BID-#{bid}-batches-failed",
|
370
372
|
"BID-#{bid}-jids",
|
371
373
|
)
|
372
374
|
end
|
@@ -87,13 +87,16 @@ module CanvasSync
|
|
87
87
|
def success(bid, status, parent_bid)
|
88
88
|
return unless parent_bid
|
89
89
|
|
90
|
-
_, _, success, _, complete, pending, children, failure = Batch.redis do |r|
|
90
|
+
_, _, success, _, _, complete, pending, children, failure = Batch.redis do |r|
|
91
91
|
r.multi do
|
92
|
-
r.sadd("BID-#{parent_bid}-success", bid)
|
93
|
-
r.expire("BID-#{parent_bid}-success", Batch::BID_EXPIRE_TTL)
|
94
|
-
r.scard("BID-#{parent_bid}-success")
|
95
|
-
|
96
|
-
r.
|
92
|
+
r.sadd("BID-#{parent_bid}-batches-success", bid)
|
93
|
+
r.expire("BID-#{parent_bid}-batches-success", Batch::BID_EXPIRE_TTL)
|
94
|
+
r.scard("BID-#{parent_bid}-batches-success")
|
95
|
+
|
96
|
+
r.srem("BID-#{parent_bid}-batches-failed", bid)
|
97
|
+
r.sadd("BID-#{parent_bid}-batches-complete", bid)
|
98
|
+
r.scard("BID-#{parent_bid}-batches-complete")
|
99
|
+
|
97
100
|
r.hincrby("BID-#{parent_bid}", "pending", 0)
|
98
101
|
r.hincrby("BID-#{parent_bid}", "children", 0)
|
99
102
|
r.scard("BID-#{parent_bid}-failed")
|
@@ -112,7 +115,7 @@ module CanvasSync
|
|
112
115
|
r.multi do
|
113
116
|
r.hincrby("BID-#{bid}", "pending", 0)
|
114
117
|
r.hincrby("BID-#{bid}", "children", 0)
|
115
|
-
r.scard("BID-#{bid}-success")
|
118
|
+
r.scard("BID-#{bid}-batches-success")
|
116
119
|
end
|
117
120
|
end
|
118
121
|
|
@@ -127,10 +130,11 @@ module CanvasSync
|
|
127
130
|
# callback may add more jobs to the parent batch
|
128
131
|
|
129
132
|
Batch.logger.debug {"Finalize parent complete bid: #{parent_bid}"}
|
130
|
-
_, complete, pending, children, failure = Batch.redis do |r|
|
133
|
+
_, _, complete, pending, children, failure = Batch.redis do |r|
|
131
134
|
r.multi do
|
132
|
-
r.sadd("BID-#{parent_bid}-complete", bid)
|
133
|
-
r.
|
135
|
+
r.sadd("BID-#{parent_bid}-batches-complete", bid)
|
136
|
+
r.sadd("BID-#{parent_bid}-batches-failed", bid)
|
137
|
+
r.scard("BID-#{parent_bid}-batches-complete")
|
134
138
|
r.hincrby("BID-#{parent_bid}", "pending", 0)
|
135
139
|
r.hincrby("BID-#{parent_bid}", "children", 0)
|
136
140
|
r.scard("BID-#{parent_bid}-failed")
|
@@ -104,6 +104,16 @@ module CanvasSync
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
# Legacy Support
|
108
|
+
def merge_options(job, options)
|
109
|
+
matching_jobs = find_matching_jobs(sub_type)
|
110
|
+
|
111
|
+
matching_jobs.each do |j|
|
112
|
+
j[:options] ||= {}
|
113
|
+
j[:options].deep_merge!(options)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
107
117
|
private
|
108
118
|
|
109
119
|
def find_matching_jobs(search_job, parent_job = self.base_job)
|
@@ -40,10 +40,26 @@ module CanvasSync
|
|
40
40
|
'true' == Batch.redis { |r| r.hget("BID-#{bid}", 'complete') }
|
41
41
|
end
|
42
42
|
|
43
|
+
def success?
|
44
|
+
'true' == Batch.redis { |r| r.hget("BID-#{bid}", 'success') }
|
45
|
+
end
|
46
|
+
|
43
47
|
def child_count
|
44
48
|
Batch.redis { |r| r.hget("BID-#{bid}", 'children') }.to_i
|
45
49
|
end
|
46
50
|
|
51
|
+
def completed_children_count
|
52
|
+
Batch.redis { |r| r.scard("BID-#{bid}-batches-complete") }.to_i
|
53
|
+
end
|
54
|
+
|
55
|
+
def successful_children_count
|
56
|
+
Batch.redis { |r| r.scard("BID-#{bid}-batches-success") }.to_i
|
57
|
+
end
|
58
|
+
|
59
|
+
def failed_children_count
|
60
|
+
Batch.redis { |r| r.scard("BID-#{bid}-batches-failed") }.to_i
|
61
|
+
end
|
62
|
+
|
47
63
|
def data
|
48
64
|
{
|
49
65
|
bid: bid,
|
@@ -52,9 +68,13 @@ module CanvasSync
|
|
52
68
|
pending: pending,
|
53
69
|
created_at: created_at,
|
54
70
|
complete: complete?,
|
71
|
+
success: success?,
|
55
72
|
failure_info: failure_info,
|
56
73
|
parent_bid: parent_bid,
|
57
|
-
child_count: child_count
|
74
|
+
child_count: child_count,
|
75
|
+
completed_children_count: completed_children_count,
|
76
|
+
successful_children_count: successful_children_count,
|
77
|
+
failed_children_count: failed_children_count,
|
58
78
|
}
|
59
79
|
end
|
60
80
|
end
|
@@ -15,6 +15,7 @@ module CanvasSync
|
|
15
15
|
JobBatches::Batch.new.tap do |b|
|
16
16
|
b.description = "CanvasSync Root Batch"
|
17
17
|
b.on(:complete, "#{self.class.to_s}.batch_completed", sync_batch_id: sync_batch.id)
|
18
|
+
b.on(:success, "#{self.class.to_s}.batch_completed", sync_batch_id: sync_batch.id)
|
18
19
|
b.context = globals
|
19
20
|
b.jobs do
|
20
21
|
JobBatches::SerialBatchJob.perform_now(chain_definition)
|
@@ -25,7 +26,7 @@ module CanvasSync
|
|
25
26
|
def self.batch_completed(status, options)
|
26
27
|
sbatch = SyncBatch.find(options['sync_batch_id'])
|
27
28
|
sbatch.update!(
|
28
|
-
status: status.
|
29
|
+
status: status.success? ? 'completed' : 'failed',
|
29
30
|
completed_at: DateTime.now,
|
30
31
|
)
|
31
32
|
end
|
data/lib/canvas_sync/version.rb
CHANGED
@@ -182,12 +182,12 @@ RSpec.describe CanvasSync::JobBatches::Batch do
|
|
182
182
|
context 'complete' do
|
183
183
|
before { batch.on(:complete, Object) }
|
184
184
|
# before { batch.increment_job_queue(bid) }
|
185
|
-
before { batch.jobs do TestWorker.perform_async end }
|
186
|
-
before { CanvasSync::JobBatches::Batch.process_failed_job(bid, 'failed-job-id') }
|
185
|
+
# before { batch.jobs do TestWorker.perform_async end }
|
186
|
+
# before { CanvasSync::JobBatches::Batch.process_failed_job(bid, 'failed-job-id') }
|
187
187
|
|
188
188
|
it 'tries to call complete callback' do
|
189
189
|
expect(CanvasSync::JobBatches::Batch).to receive(:enqueue_callbacks).with(:complete, bid)
|
190
|
-
CanvasSync::JobBatches::Batch.
|
190
|
+
CanvasSync::JobBatches::Batch.process_failed_job(bid, 'failed-job-id')
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
@@ -199,6 +199,15 @@ RSpec.describe CanvasSync::JobBatches::Batch do
|
|
199
199
|
CanvasSync::JobBatches::Batch.process_successful_job(bid, jid)
|
200
200
|
end
|
201
201
|
|
202
|
+
it 'tries to call success callback after a previous failure' do
|
203
|
+
expect(CanvasSync::JobBatches::Batch).to receive(:enqueue_callbacks).with(:complete, bid).ordered
|
204
|
+
CanvasSync::JobBatches::Batch.process_failed_job(bid, jid)
|
205
|
+
|
206
|
+
expect(CanvasSync::JobBatches::Batch).to receive(:enqueue_callbacks).with(:complete, bid).ordered
|
207
|
+
expect(CanvasSync::JobBatches::Batch).to receive(:enqueue_callbacks).with(:success, bid).ordered
|
208
|
+
CanvasSync::JobBatches::Batch.process_successful_job(bid, jid)
|
209
|
+
end
|
210
|
+
|
202
211
|
it 'cleanups redis key' do
|
203
212
|
CanvasSync::JobBatches::Batch.process_successful_job(bid, jid)
|
204
213
|
expect(CanvasSync::JobBatches::Batch.redis { |r| r.get("BID-#{bid}-pending") }.to_i).to eq(0)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canvas_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.17.0.
|
4
|
+
version: 0.17.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Collings
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|