canvas_sync 0.17.35 → 0.17.37
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/engine.rb +6 -0
- data/lib/canvas_sync/job_batches/active_job.rb +108 -0
- data/lib/canvas_sync/job_batches/batch.rb +7 -4
- data/lib/canvas_sync/job_batches/callback.rb +1 -13
- data/lib/canvas_sync/job_batches/jobs/base_job.rb +1 -1
- data/lib/canvas_sync/job_batches/jobs/managed_batch_job.rb +2 -2
- data/lib/canvas_sync/job_batches/pool.rb +2 -2
- data/lib/canvas_sync/job_batches/sidekiq.rb +21 -7
- data/lib/canvas_sync/version.rb +1 -1
- data/spec/dummy/log/test.log +23910 -0
- data/spec/job_batching/active_job_spec.rb +107 -0
- data/spec/job_batching/batch_spec.rb +1 -1
- metadata +5 -5
- data/lib/canvas_sync/job_batches/batch_aware_job.rb +0 -63
- data/spec/job_batching/batch_aware_job_spec.rb +0 -101
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe CanvasSync::JobBatches::ActiveJob do
|
4
|
+
describe CanvasSync::JobBatches::ActiveJob::BatchAwareJob do
|
5
|
+
include ActiveJob::TestHelper
|
6
|
+
|
7
|
+
after do
|
8
|
+
clear_enqueued_jobs
|
9
|
+
clear_performed_jobs
|
10
|
+
end
|
11
|
+
|
12
|
+
context "When Performing" do
|
13
|
+
context 'when without batch' do
|
14
|
+
it 'just yields' do
|
15
|
+
expect(CanvasSync::JobBatches::Batch).not_to receive(:process_successful_job)
|
16
|
+
expect(CanvasSync::JobBatches::Batch).not_to receive(:process_failed_job)
|
17
|
+
expect_any_instance_of(BatchTestJobBase).to receive(:perform)
|
18
|
+
|
19
|
+
BatchTestJobBase.perform_now
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when in batch' do
|
24
|
+
let(:bid) { 'SAMPLEBID' }
|
25
|
+
|
26
|
+
context 'when successful' do
|
27
|
+
it 'yields' do
|
28
|
+
expect_any_instance_of(BatchTestJobBase).to receive(:perform)
|
29
|
+
BatchTestJobBase.perform_now
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'calls process_successful_job' do
|
33
|
+
job = BatchTestJobBase.new
|
34
|
+
job.instance_variable_set(:@bid, bid)
|
35
|
+
expect(CanvasSync::JobBatches::Batch).to receive(:process_successful_job).with(bid, job.job_id)
|
36
|
+
job.perform_now
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'when failed' do
|
41
|
+
it 'calls process_failed_job and reraises exception' do
|
42
|
+
reraised = false
|
43
|
+
job = FailingBatchTestJobBase.new
|
44
|
+
job.instance_variable_set(:@bid, bid)
|
45
|
+
expect(CanvasSync::JobBatches::Batch).to receive(:process_failed_job)
|
46
|
+
begin
|
47
|
+
job.perform_now
|
48
|
+
rescue
|
49
|
+
reraised = true
|
50
|
+
end
|
51
|
+
expect(reraised).to be_truthy
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "When Enqueueing" do
|
58
|
+
context 'when without batch' do
|
59
|
+
it 'just yields' do
|
60
|
+
expect(CanvasSync::JobBatches::Batch).not_to receive(:increment_job_queue)
|
61
|
+
BatchTestJobBase.perform_later
|
62
|
+
expect(BatchTestJobBase).to have_been_enqueued
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when in batch' do
|
67
|
+
let(:bid) { 'SAMPLEBID' }
|
68
|
+
|
69
|
+
before do
|
70
|
+
Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY] = CanvasSync::JobBatches::Batch.new(bid)
|
71
|
+
Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY].instance_variable_set(:@open, true)
|
72
|
+
end
|
73
|
+
after { Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY] = nil }
|
74
|
+
|
75
|
+
it 'yields' do
|
76
|
+
expect {
|
77
|
+
BatchTestJobBase.perform_later
|
78
|
+
}.to enqueue_job(BatchTestJobBase)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'assigns bid to job metadata' do
|
82
|
+
job = BatchTestJobBase.perform_later
|
83
|
+
expect(job.bid).to eq bid
|
84
|
+
expect(job.serialize['batch_id']).to eq bid
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'worker' do
|
90
|
+
it 'defines method bid' do
|
91
|
+
expect(ActiveJob::Base.instance_methods).to include(:bid)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'defines method batch' do
|
95
|
+
expect(ActiveJob::Base.instance_methods).to include(:batch)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'defines method valid_within_batch?' do
|
99
|
+
expect(ActiveJob::Base.instance_methods).to include(:valid_within_batch?)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ".handle_job_death" do
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
@@ -338,7 +338,7 @@ RSpec.describe CanvasSync::JobBatches::Batch do
|
|
338
338
|
|
339
339
|
context 'With ActiveJob Adapter' do
|
340
340
|
around(:all) do |block|
|
341
|
-
CanvasSync::JobBatches::Batch::Callback.worker_class = CanvasSync::JobBatches::
|
341
|
+
CanvasSync::JobBatches::Batch::Callback.worker_class = CanvasSync::JobBatches::ActiveJob::ActiveJobCallbackWorker
|
342
342
|
block.run
|
343
343
|
end
|
344
344
|
|
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.
|
4
|
+
version: 0.17.37
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Collings
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -434,8 +434,8 @@ files:
|
|
434
434
|
- lib/canvas_sync/importers/bulk_importer.rb
|
435
435
|
- lib/canvas_sync/importers/legacy_importer.rb
|
436
436
|
- lib/canvas_sync/job.rb
|
437
|
+
- lib/canvas_sync/job_batches/active_job.rb
|
437
438
|
- lib/canvas_sync/job_batches/batch.rb
|
438
|
-
- lib/canvas_sync/job_batches/batch_aware_job.rb
|
439
439
|
- lib/canvas_sync/job_batches/callback.rb
|
440
440
|
- lib/canvas_sync/job_batches/chain_builder.rb
|
441
441
|
- lib/canvas_sync/job_batches/context_hash.rb
|
@@ -642,7 +642,7 @@ files:
|
|
642
642
|
- spec/factories/submission_factory.rb
|
643
643
|
- spec/factories/term_factory.rb
|
644
644
|
- spec/factories/user_factory.rb
|
645
|
-
- spec/job_batching/
|
645
|
+
- spec/job_batching/active_job_spec.rb
|
646
646
|
- spec/job_batching/batch_spec.rb
|
647
647
|
- spec/job_batching/callback_spec.rb
|
648
648
|
- spec/job_batching/context_hash_spec.rb
|
@@ -853,7 +853,7 @@ test_files:
|
|
853
853
|
- spec/factories/submission_factory.rb
|
854
854
|
- spec/factories/term_factory.rb
|
855
855
|
- spec/factories/user_factory.rb
|
856
|
-
- spec/job_batching/
|
856
|
+
- spec/job_batching/active_job_spec.rb
|
857
857
|
- spec/job_batching/batch_spec.rb
|
858
858
|
- spec/job_batching/callback_spec.rb
|
859
859
|
- spec/job_batching/context_hash_spec.rb
|
@@ -1,63 +0,0 @@
|
|
1
|
-
module CanvasSync
|
2
|
-
module JobBatches
|
3
|
-
module BatchAwareJob
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
included do
|
7
|
-
around_perform do |job, block|
|
8
|
-
if (@bid) # This _must_ be @bid - not just bid
|
9
|
-
prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY]
|
10
|
-
begin
|
11
|
-
Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(@bid)
|
12
|
-
block.call
|
13
|
-
Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes
|
14
|
-
Batch.process_successful_job(@bid, job_id)
|
15
|
-
rescue
|
16
|
-
Batch.process_failed_job(@bid, job_id)
|
17
|
-
raise
|
18
|
-
ensure
|
19
|
-
Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch
|
20
|
-
end
|
21
|
-
else
|
22
|
-
block.call
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
around_enqueue do |job, block|
|
27
|
-
if (batch = Thread.current[CURRENT_BATCH_THREAD_KEY])
|
28
|
-
@bid = batch.bid
|
29
|
-
batch.increment_job_queue(job_id) if @bid
|
30
|
-
end
|
31
|
-
block.call
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def bid
|
36
|
-
@bid || Thread.current[CURRENT_BATCH_THREAD_KEY]&.bid
|
37
|
-
end
|
38
|
-
|
39
|
-
def batch
|
40
|
-
Thread.current[CURRENT_BATCH_THREAD_KEY]
|
41
|
-
end
|
42
|
-
|
43
|
-
def batch_context
|
44
|
-
batch&.context || {}
|
45
|
-
end
|
46
|
-
|
47
|
-
def valid_within_batch?
|
48
|
-
batch.valid?
|
49
|
-
end
|
50
|
-
|
51
|
-
def serialize
|
52
|
-
super.tap do |data|
|
53
|
-
data['batch_id'] = @bid # This _must_ be @bid - not just bid
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def deserialize(data)
|
58
|
-
super
|
59
|
-
@bid = data['batch_id']
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe CanvasSync::JobBatches::BatchAwareJob do
|
4
|
-
include ActiveJob::TestHelper
|
5
|
-
|
6
|
-
after do
|
7
|
-
clear_enqueued_jobs
|
8
|
-
clear_performed_jobs
|
9
|
-
end
|
10
|
-
|
11
|
-
context "When Performing" do
|
12
|
-
context 'when without batch' do
|
13
|
-
it 'just yields' do
|
14
|
-
expect(CanvasSync::JobBatches::Batch).not_to receive(:process_successful_job)
|
15
|
-
expect(CanvasSync::JobBatches::Batch).not_to receive(:process_failed_job)
|
16
|
-
expect_any_instance_of(BatchTestJobBase).to receive(:perform)
|
17
|
-
|
18
|
-
BatchTestJobBase.perform_now
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
context 'when in batch' do
|
23
|
-
let(:bid) { 'SAMPLEBID' }
|
24
|
-
|
25
|
-
context 'when successful' do
|
26
|
-
it 'yields' do
|
27
|
-
expect_any_instance_of(BatchTestJobBase).to receive(:perform)
|
28
|
-
BatchTestJobBase.perform_now
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'calls process_successful_job' do
|
32
|
-
job = BatchTestJobBase.new
|
33
|
-
job.instance_variable_set(:@bid, bid)
|
34
|
-
expect(CanvasSync::JobBatches::Batch).to receive(:process_successful_job).with(bid, job.job_id)
|
35
|
-
job.perform_now
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context 'when failed' do
|
40
|
-
it 'calls process_failed_job and reraises exception' do
|
41
|
-
reraised = false
|
42
|
-
job = FailingBatchTestJobBase.new
|
43
|
-
job.instance_variable_set(:@bid, bid)
|
44
|
-
expect(CanvasSync::JobBatches::Batch).to receive(:process_failed_job)
|
45
|
-
begin
|
46
|
-
job.perform_now
|
47
|
-
rescue
|
48
|
-
reraised = true
|
49
|
-
end
|
50
|
-
expect(reraised).to be_truthy
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "When Enqueueing" do
|
57
|
-
context 'when without batch' do
|
58
|
-
it 'just yields' do
|
59
|
-
expect(CanvasSync::JobBatches::Batch).not_to receive(:increment_job_queue)
|
60
|
-
BatchTestJobBase.perform_later
|
61
|
-
expect(BatchTestJobBase).to have_been_enqueued
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
context 'when in batch' do
|
66
|
-
let(:bid) { 'SAMPLEBID' }
|
67
|
-
|
68
|
-
before do
|
69
|
-
Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY] = CanvasSync::JobBatches::Batch.new(bid)
|
70
|
-
Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY].instance_variable_set(:@open, true)
|
71
|
-
end
|
72
|
-
after { Thread.current[CanvasSync::JobBatches::CURRENT_BATCH_THREAD_KEY] = nil }
|
73
|
-
|
74
|
-
it 'yields' do
|
75
|
-
expect {
|
76
|
-
BatchTestJobBase.perform_later
|
77
|
-
}.to enqueue_job(BatchTestJobBase)
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'assigns bid to job metadata' do
|
81
|
-
job = BatchTestJobBase.perform_later
|
82
|
-
expect(job.bid).to eq bid
|
83
|
-
expect(job.serialize['batch_id']).to eq bid
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'worker' do
|
89
|
-
it 'defines method bid' do
|
90
|
-
expect(ActiveJob::Base.instance_methods).to include(:bid)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'defines method batch' do
|
94
|
-
expect(ActiveJob::Base.instance_methods).to include(:batch)
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'defines method valid_within_batch?' do
|
98
|
-
expect(ActiveJob::Base.instance_methods).to include(:valid_within_batch?)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|