canvas_sync 0.16.5 → 0.17.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +49 -137
  3. data/app/models/canvas_sync/sync_batch.rb +5 -0
  4. data/db/migrate/20201018210836_create_canvas_sync_sync_batches.rb +11 -0
  5. data/lib/canvas_sync.rb +35 -97
  6. data/lib/canvas_sync/importers/bulk_importer.rb +4 -7
  7. data/lib/canvas_sync/job.rb +4 -10
  8. data/lib/canvas_sync/job_batches/batch.rb +403 -0
  9. data/lib/canvas_sync/job_batches/batch_aware_job.rb +62 -0
  10. data/lib/canvas_sync/job_batches/callback.rb +152 -0
  11. data/lib/canvas_sync/job_batches/chain_builder.rb +220 -0
  12. data/lib/canvas_sync/job_batches/context_hash.rb +147 -0
  13. data/lib/canvas_sync/job_batches/jobs/base_job.rb +7 -0
  14. data/lib/canvas_sync/job_batches/jobs/concurrent_batch_job.rb +19 -0
  15. data/lib/canvas_sync/job_batches/jobs/serial_batch_job.rb +75 -0
  16. data/lib/canvas_sync/job_batches/sidekiq.rb +93 -0
  17. data/lib/canvas_sync/job_batches/status.rb +83 -0
  18. data/lib/canvas_sync/jobs/begin_sync_chain_job.rb +35 -0
  19. data/lib/canvas_sync/jobs/report_checker.rb +3 -6
  20. data/lib/canvas_sync/jobs/report_processor_job.rb +2 -5
  21. data/lib/canvas_sync/jobs/report_starter.rb +28 -20
  22. data/lib/canvas_sync/jobs/sync_accounts_job.rb +3 -5
  23. data/lib/canvas_sync/jobs/sync_admins_job.rb +2 -4
  24. data/lib/canvas_sync/jobs/sync_assignment_groups_job.rb +2 -4
  25. data/lib/canvas_sync/jobs/sync_assignments_job.rb +2 -4
  26. data/lib/canvas_sync/jobs/sync_context_module_items_job.rb +2 -4
  27. data/lib/canvas_sync/jobs/sync_context_modules_job.rb +2 -4
  28. data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +4 -34
  29. data/lib/canvas_sync/jobs/sync_roles_job.rb +2 -5
  30. data/lib/canvas_sync/jobs/sync_simple_table_job.rb +11 -32
  31. data/lib/canvas_sync/jobs/sync_submissions_job.rb +2 -4
  32. data/lib/canvas_sync/jobs/sync_terms_job.rb +25 -8
  33. data/lib/canvas_sync/processors/assignment_groups_processor.rb +2 -3
  34. data/lib/canvas_sync/processors/assignments_processor.rb +2 -3
  35. data/lib/canvas_sync/processors/context_module_items_processor.rb +2 -3
  36. data/lib/canvas_sync/processors/context_modules_processor.rb +2 -3
  37. data/lib/canvas_sync/processors/normal_processor.rb +1 -2
  38. data/lib/canvas_sync/processors/provisioning_report_processor.rb +2 -10
  39. data/lib/canvas_sync/processors/submissions_processor.rb +2 -3
  40. data/lib/canvas_sync/version.rb +1 -1
  41. data/spec/canvas_sync/canvas_sync_spec.rb +136 -153
  42. data/spec/canvas_sync/jobs/job_spec.rb +9 -17
  43. data/spec/canvas_sync/jobs/report_checker_spec.rb +1 -3
  44. data/spec/canvas_sync/jobs/report_processor_job_spec.rb +0 -3
  45. data/spec/canvas_sync/jobs/report_starter_spec.rb +19 -28
  46. data/spec/canvas_sync/jobs/sync_admins_job_spec.rb +1 -4
  47. data/spec/canvas_sync/jobs/sync_assignment_groups_job_spec.rb +2 -1
  48. data/spec/canvas_sync/jobs/sync_assignments_job_spec.rb +3 -2
  49. data/spec/canvas_sync/jobs/sync_context_module_items_job_spec.rb +3 -2
  50. data/spec/canvas_sync/jobs/sync_context_modules_job_spec.rb +3 -2
  51. data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +3 -35
  52. data/spec/canvas_sync/jobs/sync_roles_job_spec.rb +1 -4
  53. data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +5 -12
  54. data/spec/canvas_sync/jobs/sync_submissions_job_spec.rb +2 -1
  55. data/spec/canvas_sync/jobs/sync_terms_job_spec.rb +1 -4
  56. data/spec/dummy/config/environments/test.rb +2 -0
  57. data/spec/dummy/db/schema.rb +9 -1
  58. data/spec/job_batching/batch_aware_job_spec.rb +100 -0
  59. data/spec/job_batching/batch_spec.rb +372 -0
  60. data/spec/job_batching/callback_spec.rb +38 -0
  61. data/spec/job_batching/flow_spec.rb +88 -0
  62. data/spec/job_batching/integration/integration.rb +57 -0
  63. data/spec/job_batching/integration/nested.rb +88 -0
  64. data/spec/job_batching/integration/simple.rb +47 -0
  65. data/spec/job_batching/integration/workflow.rb +134 -0
  66. data/spec/job_batching/integration_helper.rb +48 -0
  67. data/spec/job_batching/sidekiq_spec.rb +124 -0
  68. data/spec/job_batching/status_spec.rb +92 -0
  69. data/spec/job_batching/support/base_job.rb +14 -0
  70. data/spec/job_batching/support/sample_callback.rb +2 -0
  71. data/spec/spec_helper.rb +17 -0
  72. metadata +85 -8
  73. data/lib/canvas_sync/job_chain.rb +0 -102
  74. data/lib/canvas_sync/jobs/fork_gather.rb +0 -74
  75. data/spec/canvas_sync/jobs/fork_gather_spec.rb +0 -73
@@ -8,16 +8,15 @@ module CanvasSync
8
8
  # @param options [Hash]
9
9
  class SubmissionsProcessor < ReportProcessor
10
10
  def self.process(report_file_path, _options, report_id)
11
- new(report_file_path, _options)
11
+ new(report_file_path)
12
12
  end
13
13
 
14
- def initialize(report_file_path, options)
14
+ def initialize(report_file_path)
15
15
  CanvasSync::Importers::BulkImporter.import(
16
16
  report_file_path,
17
17
  mapping[:submissions][:report_columns],
18
18
  Submission,
19
19
  mapping[:submissions][:conflict_target].to_sym,
20
- import_args: options
21
20
  )
22
21
  end
23
22
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.16.5".freeze
2
+ VERSION = "0.17.0.beta5".freeze
3
3
  end
@@ -3,13 +3,12 @@ require 'spec_helper'
3
3
  RSpec.describe CanvasSync do
4
4
  describe '.provisioning_sync' do
5
5
  it 'invokes the first job in the queue and passes on the rest of the job chain' do
6
- expected_job_chain = CanvasSync.default_provisioning_report_chain(['courses'], nil).chain_data
7
- first_job = expected_job_chain[:jobs].shift
6
+ expected_job_chain = CanvasSync.default_provisioning_report_chain(['courses'], term_scope: nil).normalize![:parameters][0]
8
7
 
9
- expect(CanvasSync::Jobs::SyncTermsJob).to receive(:perform_later)
8
+ expect(CanvasSync::Jobs::BeginSyncChainJob).to receive(:perform_later)
10
9
  .with(
11
10
  expected_job_chain,
12
- first_job[:options]
11
+ anything
13
12
  )
14
13
 
15
14
  CanvasSync.provisioning_sync(['courses'])
@@ -25,32 +24,44 @@ RSpec.describe CanvasSync do
25
24
 
26
25
  describe '.default_provisioning_report_chain' do
27
26
  it 'splits an options: Hash into options for separate models' do
28
- chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], :active, options: {
27
+ chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], term_scope: :active, options: {
29
28
  terms: { a: 1 },
30
29
  users: { b: 2 },
31
30
  provisioning: { c: 3 },
32
31
  global: { d: 4 },
33
32
  })
34
- expect(chain.chain_data).to eq({
35
- jobs: [
36
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: { a: 1 } },
37
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { models: ['users'], b: 2 } },
38
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'], c: 3 } }
39
- ],
40
- global_options: { legacy_support: false, d: 4 }
33
+ expect(chain.normalize!).to eq({
34
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
35
+ :parameters => [[
36
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
37
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"], :b=>2}},
38
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
39
+ :term_scope=>"active",
40
+ :sub_jobs=>[
41
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"], :c=>3}}
42
+ ]
43
+ }]}
44
+ ]]}
45
+ ], {:legacy_support=>false, :updated_after=>nil, :d=>4}],
41
46
  })
42
47
  end
43
48
 
44
49
  context 'we are syncing users with a term scope' do
45
50
  it 'syncs the users in a separate job that runs first' do
46
- chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], :active)
47
- expect(chain.chain_data).to eq({
48
- jobs: [
49
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
50
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { models: ['users'] } },
51
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } }
52
- ],
53
- global_options: { legacy_support: false }
51
+ chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'], term_scope: :active)
52
+ expect(chain.normalize!).to eq({
53
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
54
+ :parameters => [[
55
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
56
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users"]}},
57
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
58
+ :term_scope=>"active",
59
+ :sub_jobs=>[
60
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
61
+ ]
62
+ }]}
63
+ ]]}
64
+ ], {:legacy_support=>false, :updated_after=>nil}]
54
65
  })
55
66
  end
56
67
  end
@@ -58,26 +69,38 @@ RSpec.describe CanvasSync do
58
69
  context 'we are syncing users without a term scope' do
59
70
  it 'syncs users along with the rest of the provisioning report' do
60
71
  chain = CanvasSync.default_provisioning_report_chain(['users', 'courses'])
61
- expect(chain.chain_data).to eq({
62
- jobs: [
63
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
64
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['users', 'courses'] } }
65
- ],
66
- global_options: { legacy_support: false }
72
+ expect(chain.normalize!).to eq({
73
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
74
+ :parameters => [[
75
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
76
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
77
+ :term_scope=>nil,
78
+ :sub_jobs=>[
79
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "courses"]}}
80
+ ]
81
+ }]}
82
+ ]]}
83
+ ], {:legacy_support=>false, :updated_after=>nil}],
67
84
  })
68
85
  end
69
86
  end
70
87
 
71
88
  context 'we are syncing roles with a term scope' do
72
89
  it 'syncs the roles in a separate job that runs first' do
73
- chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'], :active)
74
- expect(chain.chain_data).to eq({
75
- jobs: [
76
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
77
- { job: CanvasSync::Jobs::SyncRolesJob.to_s, options: {} },
78
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } }
79
- ],
80
- global_options: { legacy_support: false }
90
+ chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'], term_scope: :active)
91
+ expect(chain.normalize!).to eq({
92
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
93
+ :parameters => [[
94
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
95
+ {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
96
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
97
+ :term_scope=>"active",
98
+ :sub_jobs=>[
99
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
100
+ ]
101
+ }]}
102
+ ]]}
103
+ ], {:legacy_support=>false, :updated_after=>nil}],
81
104
  })
82
105
  end
83
106
  end
@@ -85,27 +108,39 @@ RSpec.describe CanvasSync do
85
108
  context 'we are syncing roles without a term scope' do
86
109
  it 'syncs roles separately even with no term scope' do
87
110
  chain = CanvasSync.default_provisioning_report_chain(['roles', 'courses'])
88
- expect(chain.chain_data).to eq({
89
- jobs: [
90
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
91
- { job: CanvasSync::Jobs::SyncRolesJob.to_s, options: {} },
92
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['courses'] } }
93
- ],
94
- global_options: { legacy_support: false }
111
+ expect(chain.normalize!).to eq({
112
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
113
+ :parameters => [[
114
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
115
+ {:job=>"CanvasSync::Jobs::SyncRolesJob", :options=>{}},
116
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
117
+ :term_scope=>nil,
118
+ :sub_jobs=>[
119
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
120
+ ]
121
+ }]}
122
+ ]]}
123
+ ], {:legacy_support=>false, :updated_after=>nil}],
95
124
  })
96
125
  end
97
126
  end
98
127
 
99
128
  context 'we are syncing admins with a term scope' do
100
129
  it 'syncs the admins in a separate job that runs first' do
101
- chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'], :active)
102
- expect(chain.chain_data).to eq({
103
- jobs: [
104
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
105
- { job: CanvasSync::Jobs::SyncAdminsJob.to_s, options: {} },
106
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: 'active', models: ['courses'] } }
107
- ],
108
- global_options: { legacy_support: false }
130
+ chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'], term_scope: :active)
131
+ expect(chain.normalize!).to eq({
132
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
133
+ :parameters => [[
134
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
135
+ {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
136
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
137
+ :term_scope=>"active",
138
+ :sub_jobs=>[
139
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
140
+ ]
141
+ }]}
142
+ ]]}
143
+ ], {:legacy_support=>false, :updated_after=>nil}],
109
144
  })
110
145
  end
111
146
  end
@@ -113,13 +148,19 @@ RSpec.describe CanvasSync do
113
148
  context 'we are syncing admins without a term scope' do
114
149
  it 'syncs admins separately even with no term scope' do
115
150
  chain = CanvasSync.default_provisioning_report_chain(['admins', 'courses'])
116
- expect(chain.chain_data).to eq({
117
- jobs: [
118
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
119
- { job: CanvasSync::Jobs::SyncAdminsJob.to_s, options: {} },
120
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: ['courses'] } }
121
- ],
122
- global_options: { legacy_support: false }
151
+ expect(chain.normalize!).to eq({
152
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
153
+ :parameters => [[
154
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
155
+ {:job=>"CanvasSync::Jobs::SyncAdminsJob", :options=>{}},
156
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
157
+ :term_scope=>nil,
158
+ :sub_jobs=>[
159
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["courses"]}}
160
+ ]
161
+ }]}
162
+ ]]}
163
+ ], {:legacy_support=>false, :updated_after=>nil}],
123
164
  })
124
165
  end
125
166
  end
@@ -128,13 +169,19 @@ RSpec.describe CanvasSync do
128
169
  it "appends the SyncAssignmentsJob" do
129
170
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignments])
130
171
 
131
- expect(chain.chain_data).to eq(
132
- jobs: [
133
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
134
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } },
135
- { job: CanvasSync::Jobs::SyncAssignmentsJob.to_s, options: {} },
136
- ],
137
- global_options: { legacy_support: false },
172
+ expect(chain.normalize!).to eq(
173
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
174
+ :parameters => [[
175
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
176
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
177
+ :term_scope=>nil,
178
+ :sub_jobs=>[
179
+ {:job=>"CanvasSync::Jobs::SyncAssignmentsJob", :options=>{}},
180
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
181
+ ]
182
+ }]}
183
+ ]]}
184
+ ], {:legacy_support=>false, :updated_after=>nil}],
138
185
  )
139
186
  end
140
187
  end
@@ -143,13 +190,19 @@ RSpec.describe CanvasSync do
143
190
  it "appends the SyncSubmissionsJob" do
144
191
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments submissions])
145
192
 
146
- expect(chain.chain_data).to eq(
147
- jobs: [
148
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
149
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } },
150
- { job: CanvasSync::Jobs::SyncSubmissionsJob.to_s, options: {} },
151
- ],
152
- global_options: { legacy_support: false },
193
+ expect(chain.normalize!).to eq(
194
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
195
+ :parameters => [[
196
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
197
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
198
+ :term_scope=>nil,
199
+ :sub_jobs=>[
200
+ {:job=>"CanvasSync::Jobs::SyncSubmissionsJob", :options=>{}},
201
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
202
+ ]
203
+ }]}
204
+ ]]}
205
+ ], {:legacy_support=>false, :updated_after=>nil}],
153
206
  )
154
207
  end
155
208
  end
@@ -158,95 +211,25 @@ RSpec.describe CanvasSync do
158
211
  it "appends the SyncAssignmentGroupsJob" do
159
212
  chain = CanvasSync.default_provisioning_report_chain(%w[users enrollments assignment_groups])
160
213
 
161
- expect(chain.chain_data).to eq(
162
- jobs: [
163
- { job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} },
164
- { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: nil, models: %w[users enrollments] } },
165
- { job: CanvasSync::Jobs::SyncAssignmentGroupsJob.to_s, options: {} },
166
- ],
167
- global_options: { legacy_support: false },
214
+ expect(chain.normalize!).to eq(
215
+ :job => "CanvasSync::Jobs::BeginSyncChainJob",
216
+ :parameters => [[
217
+ {:job=>"CanvasSync::JobBatches::ConcurrentBatchJob", :parameters=>[[
218
+ {:job=>"CanvasSync::Jobs::SyncTermsJob", :parameters=>[{
219
+ :term_scope=>nil,
220
+ :sub_jobs=>[
221
+ {:job=>"CanvasSync::Jobs::SyncAssignmentGroupsJob", :options=>{}},
222
+ {:job=>"CanvasSync::Jobs::SyncProvisioningReportJob", :options=>{:models=>["users", "enrollments"]}}
223
+ ]
224
+ }]}
225
+ ]]}
226
+ ], {:legacy_support=>false, :updated_after=>nil}],
168
227
  )
169
228
  end
170
229
  end
171
230
  end
172
231
  end
173
232
 
174
- describe ".simple_report_sync" do
175
-
176
- it 'invokes the first job in the queue and passes on the rest of the job chain' do
177
- expected_job_chain = CanvasSync.simple_report_chain(
178
- [
179
- {
180
- report_name: 'proservices_provisioning_csv',
181
- model: 'users',
182
- params: {
183
- "parameters[include_deleted]" => true,
184
- "parameters[users]" => true
185
- }
186
- }
187
- ]
188
- ).chain_data
189
- first_job = expected_job_chain[:jobs].shift
190
-
191
- expect(CanvasSync::Jobs::SyncSimpleTableJob).to receive(:perform_later)
192
- .with(
193
- expected_job_chain,
194
- first_job[:options]
195
- )
196
-
197
- CanvasSync.simple_report_sync(
198
- [
199
- {
200
- report_name: 'proservices_provisioning_csv',
201
- model: 'users',
202
- params: {
203
- "parameters[include_deleted]" => true,
204
- "parameters[users]" => true
205
- }
206
- }
207
- ]
208
- )
209
- end
210
-
211
- it 'receives the job chain for the specified table' do
212
- chain = CanvasSync.simple_report_chain(
213
- [
214
- {
215
- report_name: 'proservices_provisioning_csv',
216
- model: 'users',
217
- params: {
218
- "parameters[include_deleted]" => true,
219
- "parameters[users]" => true
220
- }
221
- }
222
- ]
223
- )
224
-
225
- expected_job_chain = {
226
- jobs: [
227
- {
228
- job: CanvasSync::Jobs::SyncSimpleTableJob.to_s,
229
- options: {
230
- report_name: 'proservices_provisioning_csv',
231
- model: 'users',
232
- mapping: 'users',
233
- klass: 'User',
234
- term_scope: nil,
235
- params: {
236
- "parameters[include_deleted]" => true,
237
- "parameters[users]" => true
238
- }
239
- }
240
- }
241
- ],
242
- global_options: {}
243
- }
244
-
245
- expect(chain.chain_data).to eq(expected_job_chain)
246
-
247
- end
248
- end
249
-
250
233
  describe ".sync_scope" do
251
234
 
252
235
  end
@@ -1,14 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  class GoodJob < CanvasSync::Job
4
- def perform(job_chain, argument)
4
+ def perform(argument)
5
5
  end
6
6
  end
7
7
 
8
8
  class EvilError < StandardError; end;
9
9
 
10
10
  class BadJob < CanvasSync::Job
11
- def perform(job_chain, argument)
11
+ def perform(argument)
12
12
  raise EvilError
13
13
  end
14
14
 
@@ -25,19 +25,19 @@ RSpec.describe CanvasSync::Job do
25
25
  describe '#perform' do
26
26
  it 'creates a CanvasSync::JobLog and logs relevant data on it' do
27
27
  expect {
28
- GoodJob.perform_now({}, "argument")
28
+ GoodJob.perform_now("argument")
29
29
  }.to change { CanvasSync::JobLog.count }.by(1)
30
30
 
31
31
  job_log = CanvasSync::JobLog.last
32
32
  expect(job_log.started_at).to_not be_nil
33
33
  expect(job_log.job_class).to eq(GoodJob.to_s)
34
- expect(job_log.job_arguments).to eq([{}, "argument"])
34
+ expect(job_log.job_arguments).to eq(["argument"])
35
35
  expect(job_log.completed_at).to_not be_nil
36
36
  end
37
37
 
38
38
  it 'logs exceptions on the CanvasSync::JobLog and then re-raises' do
39
39
  expect {
40
- BadJob.perform_now({}, "argument")
40
+ BadJob.perform_now("argument")
41
41
  }.to raise_exception(StandardError)
42
42
 
43
43
  job_log = CanvasSync::JobLog.last
@@ -47,25 +47,17 @@ RSpec.describe CanvasSync::Job do
47
47
 
48
48
  it 'invokes an error handler' do
49
49
  expect(BadJob).to receive(:good_catcher).once
50
+ set_batch_context(on_failure: 'BadJob.good_catcher')
50
51
  expect {
51
- BadJob.perform_now({
52
- jobs: [],
53
- global_options: {
54
- on_failure: 'BadJob.good_catcher'
55
- }
56
- })
52
+ BadJob.perform_now()
57
53
  }.to raise_exception(StandardError)
58
54
  end
59
55
 
60
56
  it 'logs a failing error handler' do
61
57
  expect(BadJob).to receive(:bad_catcher).once.and_call_original
58
+ set_batch_context(on_failure: 'BadJob.bad_catcher')
62
59
  expect {
63
- BadJob.perform_now({
64
- jobs: [],
65
- global_options: {
66
- on_failure: 'BadJob.bad_catcher'
67
- }
68
- })
60
+ BadJob.perform_now()
69
61
  }.to raise_exception(StandardError)
70
62
  job_log = CanvasSync::JobLog.last
71
63
  expect(job_log.backtrace).to include "Error Occurred while handling an Error"