canvas_sync 0.16.4 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +235 -151
  3. data/app/controllers/{api → canvas_sync/api}/v1/health_check_controller.rb +1 -1
  4. data/app/controllers/canvas_sync/api/v1/live_events_controller.rb +122 -0
  5. data/app/models/canvas_sync/sync_batch.rb +5 -0
  6. data/config/initializers/apartment.rb +10 -1
  7. data/config/routes.rb +7 -0
  8. data/db/migrate/20170915210836_create_canvas_sync_job_log.rb +12 -31
  9. data/db/migrate/20180725155729_add_job_id_to_canvas_sync_job_logs.rb +4 -13
  10. data/db/migrate/20190916154829_add_fork_count_to_canvas_sync_job_logs.rb +3 -11
  11. data/db/migrate/20201018210836_create_canvas_sync_sync_batches.rb +11 -0
  12. data/db/migrate/20201030210836_add_full_sync_to_canvas_sync_sync_batch.rb +7 -0
  13. data/lib/canvas_sync/batch_processor.rb +41 -0
  14. data/lib/canvas_sync/concerns/ability_helper.rb +72 -0
  15. data/lib/canvas_sync/concerns/account/ancestry.rb +2 -0
  16. data/lib/canvas_sync/concerns/account/base.rb +15 -0
  17. data/lib/canvas_sync/concerns/api_syncable.rb +17 -10
  18. data/lib/canvas_sync/concerns/live_event_sync.rb +46 -0
  19. data/lib/canvas_sync/concerns/role/base.rb +57 -0
  20. data/lib/canvas_sync/concerns/sync_mapping.rb +120 -0
  21. data/lib/canvas_sync/engine.rb +80 -0
  22. data/lib/canvas_sync/generators/install_generator.rb +1 -0
  23. data/lib/canvas_sync/generators/install_live_events_generator.rb +0 -1
  24. data/lib/canvas_sync/generators/templates/migrations/create_content_migrations.rb +24 -0
  25. data/lib/canvas_sync/generators/templates/migrations/create_course_nicknames.rb +17 -0
  26. data/lib/canvas_sync/generators/templates/migrations/create_grading_period_groups.rb +18 -0
  27. data/lib/canvas_sync/generators/templates/migrations/create_grading_periods.rb +22 -0
  28. data/lib/canvas_sync/generators/templates/migrations/create_learning_outcome_results.rb +46 -0
  29. data/lib/canvas_sync/generators/templates/migrations/create_learning_outcomes.rb +30 -0
  30. data/lib/canvas_sync/generators/templates/migrations/create_rubric_assessments.rb +31 -0
  31. data/lib/canvas_sync/generators/templates/migrations/create_rubric_associations.rb +36 -0
  32. data/lib/canvas_sync/generators/templates/migrations/create_rubrics.rb +38 -0
  33. data/lib/canvas_sync/generators/templates/migrations/create_user_observers.rb +17 -0
  34. data/lib/canvas_sync/generators/templates/migrations/create_users.rb +0 -1
  35. data/lib/canvas_sync/generators/templates/models/account.rb +3 -0
  36. data/lib/canvas_sync/generators/templates/models/admin.rb +2 -0
  37. data/lib/canvas_sync/generators/templates/models/assignment.rb +3 -0
  38. data/lib/canvas_sync/generators/templates/models/assignment_group.rb +3 -0
  39. data/lib/canvas_sync/generators/templates/models/content_migration.rb +12 -0
  40. data/lib/canvas_sync/generators/templates/models/context_module.rb +3 -0
  41. data/lib/canvas_sync/generators/templates/models/context_module_item.rb +3 -0
  42. data/lib/canvas_sync/generators/templates/models/course.rb +11 -0
  43. data/lib/canvas_sync/generators/templates/models/course_nickname.rb +13 -0
  44. data/lib/canvas_sync/generators/templates/models/enrollment.rb +14 -0
  45. data/lib/canvas_sync/generators/templates/models/grading_period.rb +10 -0
  46. data/lib/canvas_sync/generators/templates/models/grading_period_group.rb +9 -0
  47. data/lib/canvas_sync/generators/templates/models/group.rb +2 -0
  48. data/lib/canvas_sync/generators/templates/models/group_membership.rb +2 -0
  49. data/lib/canvas_sync/generators/templates/models/learning_outcome.rb +24 -0
  50. data/lib/canvas_sync/generators/templates/models/learning_outcome_result.rb +48 -0
  51. data/lib/canvas_sync/generators/templates/models/pseudonym.rb +2 -0
  52. data/lib/canvas_sync/generators/templates/models/role.rb +2 -0
  53. data/lib/canvas_sync/generators/templates/models/rubric.rb +29 -0
  54. data/lib/canvas_sync/generators/templates/models/rubric_assessment.rb +17 -0
  55. data/lib/canvas_sync/generators/templates/models/rubric_association.rb +14 -0
  56. data/lib/canvas_sync/generators/templates/models/section.rb +9 -0
  57. data/lib/canvas_sync/generators/templates/models/submission.rb +3 -0
  58. data/lib/canvas_sync/generators/templates/models/term.rb +3 -0
  59. data/lib/canvas_sync/generators/templates/models/user.rb +11 -0
  60. data/lib/canvas_sync/generators/templates/models/user_observer.rb +13 -0
  61. data/lib/canvas_sync/generators/templates/services/live_events/assignment_event.rb +1 -1
  62. data/lib/canvas_sync/generators/templates/services/live_events/assignment_group_event.rb +1 -1
  63. data/lib/canvas_sync/generators/templates/services/live_events/course_event.rb +1 -3
  64. data/lib/canvas_sync/generators/templates/services/live_events/course_section_event.rb +1 -1
  65. data/lib/canvas_sync/generators/templates/services/live_events/enrollment_event.rb +1 -1
  66. data/lib/canvas_sync/generators/templates/services/live_events/grade_event.rb +1 -1
  67. data/lib/canvas_sync/generators/templates/services/live_events/module_event.rb +1 -1
  68. data/lib/canvas_sync/generators/templates/services/live_events/module_item_event.rb +1 -1
  69. data/lib/canvas_sync/generators/templates/services/live_events/submission_event.rb +1 -1
  70. data/lib/canvas_sync/generators/templates/services/live_events/syllabus_event.rb +1 -1
  71. data/lib/canvas_sync/generators/templates/services/live_events/user_event.rb +1 -3
  72. data/lib/canvas_sync/importers/bulk_importer.rb +138 -31
  73. data/lib/canvas_sync/job.rb +7 -5
  74. data/lib/canvas_sync/job_batches/active_job.rb +108 -0
  75. data/lib/canvas_sync/job_batches/batch.rb +543 -0
  76. data/lib/canvas_sync/job_batches/callback.rb +149 -0
  77. data/lib/canvas_sync/job_batches/chain_builder.rb +249 -0
  78. data/lib/canvas_sync/job_batches/context_hash.rb +159 -0
  79. data/lib/canvas_sync/job_batches/hier_batch_ids.lua +25 -0
  80. data/lib/canvas_sync/job_batches/jobs/base_job.rb +7 -0
  81. data/lib/canvas_sync/job_batches/jobs/concurrent_batch_job.rb +22 -0
  82. data/lib/canvas_sync/job_batches/jobs/managed_batch_job.rb +170 -0
  83. data/lib/canvas_sync/job_batches/jobs/serial_batch_job.rb +22 -0
  84. data/lib/canvas_sync/job_batches/pool.rb +245 -0
  85. data/lib/canvas_sync/job_batches/pool_refill.lua +47 -0
  86. data/lib/canvas_sync/job_batches/redis_model.rb +69 -0
  87. data/lib/canvas_sync/job_batches/redis_script.rb +163 -0
  88. data/lib/canvas_sync/job_batches/schedule_callback.lua +14 -0
  89. data/lib/canvas_sync/job_batches/sidekiq/web/batches_assets/css/styles.less +182 -0
  90. data/lib/canvas_sync/job_batches/sidekiq/web/batches_assets/js/batch_tree.js +108 -0
  91. data/lib/canvas_sync/job_batches/sidekiq/web/batches_assets/js/util.js +2 -0
  92. data/lib/canvas_sync/job_batches/sidekiq/web/helpers.rb +41 -0
  93. data/lib/canvas_sync/job_batches/sidekiq/web/views/_batch_tree.erb +6 -0
  94. data/lib/canvas_sync/job_batches/sidekiq/web/views/_batches_table.erb +44 -0
  95. data/lib/canvas_sync/job_batches/sidekiq/web/views/_common.erb +13 -0
  96. data/lib/canvas_sync/job_batches/sidekiq/web/views/_jobs_table.erb +21 -0
  97. data/lib/canvas_sync/job_batches/sidekiq/web/views/_pagination.erb +26 -0
  98. data/lib/canvas_sync/job_batches/sidekiq/web/views/batch.erb +81 -0
  99. data/lib/canvas_sync/job_batches/sidekiq/web/views/batches.erb +23 -0
  100. data/lib/canvas_sync/job_batches/sidekiq/web/views/pool.erb +137 -0
  101. data/lib/canvas_sync/job_batches/sidekiq/web/views/pools.erb +47 -0
  102. data/lib/canvas_sync/job_batches/sidekiq/web.rb +218 -0
  103. data/lib/canvas_sync/job_batches/sidekiq.rb +136 -0
  104. data/lib/canvas_sync/job_batches/status.rb +91 -0
  105. data/lib/canvas_sync/jobs/begin_sync_chain_job.rb +99 -0
  106. data/lib/canvas_sync/jobs/canvas_process_waiter.rb +41 -0
  107. data/lib/canvas_sync/jobs/report_checker.rb +70 -8
  108. data/lib/canvas_sync/jobs/report_processor_job.rb +4 -7
  109. data/lib/canvas_sync/jobs/report_starter.rb +34 -20
  110. data/lib/canvas_sync/jobs/sync_accounts_job.rb +3 -5
  111. data/lib/canvas_sync/jobs/sync_admins_job.rb +2 -4
  112. data/lib/canvas_sync/jobs/sync_assignment_groups_job.rb +2 -4
  113. data/lib/canvas_sync/jobs/sync_assignments_job.rb +2 -4
  114. data/lib/canvas_sync/jobs/sync_content_migrations_job.rb +20 -0
  115. data/lib/canvas_sync/jobs/sync_context_module_items_job.rb +2 -4
  116. data/lib/canvas_sync/jobs/sync_context_modules_job.rb +2 -4
  117. data/lib/canvas_sync/jobs/sync_provisioning_report_job.rb +16 -50
  118. data/lib/canvas_sync/jobs/sync_roles_job.rb +2 -5
  119. data/lib/canvas_sync/jobs/sync_rubric_assessments_job.rb +15 -0
  120. data/lib/canvas_sync/jobs/sync_rubric_associations_job.rb +15 -0
  121. data/lib/canvas_sync/jobs/sync_rubrics_job.rb +15 -0
  122. data/lib/canvas_sync/jobs/sync_simple_table_job.rb +11 -32
  123. data/lib/canvas_sync/jobs/sync_submissions_job.rb +6 -4
  124. data/lib/canvas_sync/jobs/sync_terms_job.rb +9 -8
  125. data/lib/canvas_sync/jobs/term_batches_job.rb +50 -0
  126. data/lib/canvas_sync/{generators/templates/services/live_events/base_event.rb → live_events/base_handler.rb} +6 -10
  127. data/lib/canvas_sync/live_events/process_event_job.rb +26 -0
  128. data/lib/canvas_sync/live_events.rb +38 -0
  129. data/lib/canvas_sync/misc_helper.rb +63 -0
  130. data/lib/canvas_sync/processors/assignment_groups_processor.rb +3 -8
  131. data/lib/canvas_sync/processors/assignments_processor.rb +3 -8
  132. data/lib/canvas_sync/processors/content_migrations_processor.rb +19 -0
  133. data/lib/canvas_sync/processors/context_module_items_processor.rb +3 -8
  134. data/lib/canvas_sync/processors/context_modules_processor.rb +3 -8
  135. data/lib/canvas_sync/processors/model_mappings.yml +420 -0
  136. data/lib/canvas_sync/processors/normal_processor.rb +3 -3
  137. data/lib/canvas_sync/processors/provisioning_report_processor.rb +42 -55
  138. data/lib/canvas_sync/processors/report_processor.rb +15 -9
  139. data/lib/canvas_sync/processors/rubric_assessments_processor.rb +19 -0
  140. data/lib/canvas_sync/processors/rubric_associations_processor.rb +19 -0
  141. data/lib/canvas_sync/processors/rubrics_processor.rb +19 -0
  142. data/lib/canvas_sync/processors/submissions_processor.rb +3 -8
  143. data/lib/canvas_sync/record.rb +103 -0
  144. data/lib/canvas_sync/version.rb +1 -1
  145. data/lib/canvas_sync.rb +124 -125
  146. data/spec/canvas_sync/canvas_sync_spec.rb +224 -155
  147. data/spec/canvas_sync/jobs/canvas_process_waiter_spec.rb +34 -0
  148. data/spec/canvas_sync/jobs/job_spec.rb +9 -17
  149. data/spec/canvas_sync/jobs/report_checker_spec.rb +1 -3
  150. data/spec/canvas_sync/jobs/report_processor_job_spec.rb +0 -3
  151. data/spec/canvas_sync/jobs/report_starter_spec.rb +19 -28
  152. data/spec/canvas_sync/jobs/sync_admins_job_spec.rb +1 -4
  153. data/spec/canvas_sync/jobs/sync_assignment_groups_job_spec.rb +2 -1
  154. data/spec/canvas_sync/jobs/sync_assignments_job_spec.rb +3 -2
  155. data/spec/canvas_sync/jobs/sync_content_migrations_job_spec.rb +30 -0
  156. data/spec/canvas_sync/jobs/sync_context_module_items_job_spec.rb +3 -2
  157. data/spec/canvas_sync/jobs/sync_context_modules_job_spec.rb +3 -2
  158. data/spec/canvas_sync/jobs/sync_provisioning_report_job_spec.rb +7 -41
  159. data/spec/canvas_sync/jobs/sync_roles_job_spec.rb +1 -4
  160. data/spec/canvas_sync/jobs/sync_simple_table_job_spec.rb +5 -12
  161. data/spec/canvas_sync/jobs/sync_submissions_job_spec.rb +8 -2
  162. data/spec/canvas_sync/jobs/sync_terms_job_spec.rb +1 -4
  163. data/spec/canvas_sync/live_events/live_event_sync_spec.rb +27 -0
  164. data/spec/canvas_sync/live_events/live_events_controller_spec.rb +54 -0
  165. data/spec/canvas_sync/live_events/process_event_job_spec.rb +38 -0
  166. data/spec/canvas_sync/misc_helper_spec.rb +58 -0
  167. data/spec/canvas_sync/models/assignment_spec.rb +1 -1
  168. data/spec/canvas_sync/processors/content_migrations_processor_spec.rb +13 -0
  169. data/spec/canvas_sync/processors/provisioning_report_processor_spec.rb +101 -1
  170. data/spec/canvas_sync/processors/rubric_assessments_spec.rb +16 -0
  171. data/spec/canvas_sync/processors/rubric_associations_spec.rb +16 -0
  172. data/spec/canvas_sync/processors/rubrics_processor_spec.rb +17 -0
  173. data/spec/dummy/app/models/account.rb +6 -0
  174. data/spec/dummy/app/models/admin.rb +2 -0
  175. data/spec/dummy/app/models/assignment.rb +3 -0
  176. data/spec/dummy/app/models/assignment_group.rb +3 -0
  177. data/spec/dummy/app/models/content_migration.rb +18 -0
  178. data/spec/dummy/app/models/context_module.rb +3 -0
  179. data/spec/dummy/app/models/context_module_item.rb +3 -0
  180. data/spec/dummy/app/models/course.rb +11 -0
  181. data/spec/dummy/app/models/course_nickname.rb +19 -0
  182. data/spec/dummy/app/models/enrollment.rb +14 -0
  183. data/spec/dummy/app/models/grading_period.rb +16 -0
  184. data/spec/dummy/app/models/grading_period_group.rb +15 -0
  185. data/spec/dummy/app/models/group.rb +2 -0
  186. data/spec/dummy/app/models/group_membership.rb +2 -0
  187. data/spec/dummy/app/models/learning_outcome.rb +30 -0
  188. data/spec/dummy/app/models/learning_outcome_result.rb +54 -0
  189. data/spec/dummy/app/models/pseudonym.rb +16 -0
  190. data/spec/dummy/app/models/role.rb +2 -0
  191. data/spec/dummy/app/models/rubric.rb +35 -0
  192. data/spec/dummy/app/models/rubric_assessment.rb +22 -0
  193. data/spec/dummy/app/models/rubric_association.rb +20 -0
  194. data/spec/dummy/app/models/section.rb +9 -0
  195. data/spec/dummy/app/models/submission.rb +4 -0
  196. data/spec/dummy/app/models/term.rb +3 -0
  197. data/spec/dummy/app/models/user.rb +11 -0
  198. data/spec/dummy/app/models/user_observer.rb +19 -0
  199. data/spec/dummy/app/services/live_events/assignment_event.rb +1 -1
  200. data/spec/dummy/app/services/live_events/course_event.rb +1 -3
  201. data/spec/dummy/app/services/live_events/course_section_event.rb +1 -1
  202. data/spec/dummy/app/services/live_events/enrollment_event.rb +1 -1
  203. data/spec/dummy/app/services/live_events/grade_event.rb +1 -1
  204. data/spec/dummy/app/services/live_events/module_event.rb +1 -1
  205. data/spec/dummy/app/services/live_events/module_item_event.rb +1 -1
  206. data/spec/dummy/app/services/live_events/submission_event.rb +1 -1
  207. data/spec/dummy/app/services/live_events/syllabus_event.rb +1 -1
  208. data/spec/dummy/app/services/live_events/user_event.rb +1 -3
  209. data/spec/dummy/config/environments/test.rb +2 -0
  210. data/spec/dummy/config/routes.rb +1 -0
  211. data/spec/dummy/db/migrate/20201016181346_create_pseudonyms.rb +24 -0
  212. data/spec/dummy/db/migrate/20210907233329_create_user_observers.rb +23 -0
  213. data/spec/dummy/db/migrate/20210907233330_create_grading_periods.rb +28 -0
  214. data/spec/dummy/db/migrate/20211001184920_create_grading_period_groups.rb +24 -0
  215. data/spec/dummy/db/migrate/20220308072643_create_content_migrations.rb +30 -0
  216. data/spec/dummy/db/migrate/20220712210559_create_learning_outcomes.rb +36 -0
  217. data/spec/dummy/db/migrate/{20190702203620_create_users.rb → 20220926221926_create_users.rb} +0 -1
  218. data/spec/dummy/db/migrate/20240408223326_create_course_nicknames.rb +23 -0
  219. data/spec/dummy/db/migrate/20240509105100_create_rubrics.rb +44 -0
  220. data/spec/dummy/db/migrate/20240510094100_create_rubric_associations.rb +42 -0
  221. data/spec/dummy/db/migrate/20240510101100_create_rubric_assessments.rb +37 -0
  222. data/spec/dummy/db/migrate/20240523101010_create_learning_outcome_results.rb +52 -0
  223. data/spec/dummy/db/schema.rb +244 -5
  224. data/spec/factories/user_factory.rb +0 -1
  225. data/spec/job_batching/active_job_spec.rb +107 -0
  226. data/spec/job_batching/batch_spec.rb +489 -0
  227. data/spec/job_batching/callback_spec.rb +38 -0
  228. data/spec/job_batching/context_hash_spec.rb +54 -0
  229. data/spec/job_batching/flow_spec.rb +82 -0
  230. data/spec/job_batching/integration/fail_then_succeed.rb +42 -0
  231. data/spec/job_batching/integration/integration.rb +57 -0
  232. data/spec/job_batching/integration/nested.rb +88 -0
  233. data/spec/job_batching/integration/simple.rb +47 -0
  234. data/spec/job_batching/integration/workflow.rb +134 -0
  235. data/spec/job_batching/integration_helper.rb +50 -0
  236. data/spec/job_batching/pool_spec.rb +161 -0
  237. data/spec/job_batching/sidekiq_spec.rb +125 -0
  238. data/spec/job_batching/status_spec.rb +76 -0
  239. data/spec/job_batching/support/base_job.rb +14 -0
  240. data/spec/job_batching/support/sample_callback.rb +2 -0
  241. data/spec/spec_helper.rb +17 -0
  242. data/spec/support/fixtures/reports/content_migrations.csv +3 -0
  243. data/spec/support/fixtures/reports/course_nicknames.csv +3 -0
  244. data/spec/support/fixtures/reports/grading_period_groups.csv +2 -0
  245. data/spec/support/fixtures/reports/grading_periods.csv +3 -0
  246. data/spec/support/fixtures/reports/learning_outcome_results.csv +3 -0
  247. data/spec/support/fixtures/reports/learning_outcomes.csv +3 -0
  248. data/spec/support/fixtures/reports/provisioning_csv_unzipped/courses.csv +3 -0
  249. data/spec/support/fixtures/reports/provisioning_csv_unzipped/users.csv +4 -0
  250. data/spec/support/fixtures/reports/rubric_assessments.csv +3 -0
  251. data/spec/support/fixtures/reports/rubric_associations.csv +3 -0
  252. data/spec/support/fixtures/reports/rubrics.csv +3 -0
  253. data/spec/support/fixtures/reports/user_observers.csv +3 -0
  254. data/spec/support/fixtures/reports/users.csv +3 -2
  255. data/spec/support/fixtures/reports/xlist.csv +1 -1
  256. metadata +329 -27
  257. data/app/controllers/api/v1/live_events_controller.rb +0 -18
  258. data/lib/canvas_sync/job_chain.rb +0 -57
  259. data/lib/canvas_sync/jobs/fork_gather.rb +0 -59
  260. data/spec/canvas_sync/jobs/fork_gather_spec.rb +0 -73
@@ -0,0 +1,15 @@
1
+ module CanvasSync
2
+ module Jobs
3
+ class SyncRubricsJob < ReportStarter
4
+ # @param options [Hash]
5
+ def perform(options)
6
+ super(
7
+ "rubrics_csv",
8
+ merge_report_params(options),
9
+ CanvasSync::Processors::RubricsProcessor.to_s,
10
+ {},
11
+ )
12
+ end
13
+ end
14
+ end
15
+ end
@@ -5,36 +5,19 @@ module CanvasSync
5
5
  # Starts a report processor for the specified report
6
6
  # (the specified report must be enabled)
7
7
  #
8
- # @param job_chain [Hash]
9
- # @param options [Hash]
10
- def perform(job_chain, options)
11
- if options[:term_scope]
12
- sub_reports = CanvasSync.fork(@job_log, job_chain, keys: [:canvas_term_id]) do |job_chain|
13
- Term.send(options[:term_scope]).find_each.map do |term|
14
- # Deep copy the job_chain so each report gets the correct term id passed into
15
- # its options with no side effects
16
- term_id = get_term_id(term)
17
- duped_job_chain = Marshal.load(Marshal.dump(job_chain))
18
- duped_job_chain[:global_options][:canvas_term_id] = term_id
19
- {
20
- job_chain: duped_job_chain,
21
- params: report_params(options, term_id),
22
- options: options,
23
- }
24
- end
25
- end
26
-
27
- sub_reports.each do |r|
28
- start_report(r[:params], r[:job_chain], r[:options])
29
- end
30
- else
31
- start_report(report_params(options), job_chain, options)
32
- end
8
+ # @param options [Hash] {
9
+ # report_name: "", # Name of the report in the Canvas API
10
+ # model: , # Model to map the report results as
11
+ # mapping: {} # Mapping to describe how to convert the report to the Model,
12
+ # klass: ,
13
+ # params: {}, # List of params to pass to the report
14
+ # }
15
+ def perform(options)
16
+ start_report(report_params(options), options)
33
17
  end
34
18
 
35
- def start_report(params, job_chain, options)
19
+ def start_report(params, options)
36
20
  CanvasSync::Jobs::ReportStarter.perform_later(
37
- job_chain,
38
21
  options[:report_name],
39
22
  params,
40
23
  CanvasSync::Processors::NormalProcessor.to_s,
@@ -42,15 +25,11 @@ module CanvasSync
42
25
  )
43
26
  end
44
27
 
45
- def report_params(options, canvas_term_id=nil)
28
+ def report_params(options, canvas_term_id = options[:canvas_term_id] || batch_context[:canvas_term_id])
46
29
  params = options[:params] || {}
47
30
  params["parameters[enrollment_term_id]"] = canvas_term_id if canvas_term_id
48
31
  params
49
32
  end
50
-
51
- def get_term_id(term)
52
- term.try(:canvas_id) || term.canvas_term_id
53
- end
54
33
  end
55
34
  end
56
35
  end
@@ -6,13 +6,15 @@ module CanvasSync
6
6
  # Starts a report processor for the submission report
7
7
  # (the proserv_student_submissions_csv report must be enabled)
8
8
  #
9
- # @param job_chain [Hash]
10
9
  # @param options [Hash]
11
- def perform(job_chain, options)
10
+ def perform(options)
12
11
  super(
13
- job_chain,
14
12
  "proserv_student_submissions_csv",
15
- merge_report_params(job_chain, options, { include_all: options[:include_all] }, {}),
13
+ merge_report_params(options, {
14
+ include_all: options[:include_all],
15
+ enrollment_batch_size: options[:enrollment_batch_size],
16
+ include_all_except: options[:include_all_except]
17
+ }, {}),
16
18
  CanvasSync::Processors::SubmissionsProcessor.to_s,
17
19
  {},
18
20
  )
@@ -5,16 +5,17 @@ module CanvasSync
5
5
  #
6
6
  # Terms are pre-synced so that provisioning reports can be scoped to term.
7
7
  #
8
- # @param job_chain [Hash]
9
- # @param options [Hash]
10
- def perform(job_chain, _options)
11
- CanvasSync.get_canvas_sync_client(job_chain[:global_options]).terms("self").all_pages!.each do |term_params|
12
- if job_chain[:global_options][:account_id]
8
+ # @param options [Hash] If options contains a :term_scope a seperate provisioning report
9
+ # will be started for each term in that scope. :models should be an array of
10
+ # models to sync.
11
+ def perform(options)
12
+ CanvasSync.get_canvas_sync_client(batch_context).terms("self", workflow_state: ['all']).all_pages!.each do |term_params|
13
+ if account_id = batch_context[:account_id]
13
14
  # These branches are primarily to support Legacy apps
14
15
  if Term.respond_to?(:create_or_update) && Term.method(:create_or_update).arity.abs == 2
15
- Term.create_or_update(term_params, job_chain[:global_options][:account_id])
16
+ Term.create_or_update(term_params, account_id)
16
17
  else
17
- term_params[:account_id] |= job_chain[:global_options][:account_id]
18
+ term_params[:account_id] |= account_id
18
19
  update_or_create_model(Term, term_params)
19
20
  end
20
21
  else
@@ -22,7 +23,7 @@ module CanvasSync
22
23
  end
23
24
  end
24
25
 
25
- CanvasSync.invoke_next(job_chain)
26
+ TermBatchesJob.perform_now(options)
26
27
  end
27
28
  end
28
29
  end
@@ -0,0 +1,50 @@
1
+ module CanvasSync
2
+ module Jobs
3
+ class TermBatchesJob < CanvasSync::Job
4
+ def perform(options)
5
+ if (jobs = options[:sub_jobs]).present?
6
+ context = options[:context] || {}
7
+ if options[:term_scope]
8
+ Term.send(options[:term_scope]).find_each.map do |term|
9
+ term_id = get_term_id(term)
10
+ local_context = context.merge(canvas_term_id: term_id)
11
+
12
+ # Override the delta-syncing date if:
13
+ # 1. the Term hasn't been synced before or
14
+ # 2. the Term underwent a period of not syncing
15
+ term_last_sync = CanvasSync.redis.get(self.class.last_sync_key(term_id))
16
+ if batch_context[:updated_after]
17
+ if !term_last_sync.present? || batch_context[:updated_after] > term_last_sync
18
+ local_context[:updated_after] = term_last_sync.presence
19
+ end
20
+ end
21
+
22
+ JobBatches::ManagedBatchJob.make_batch(jobs, ordered: false, concurrency: true) do |b|
23
+ b.description = "TermBatchJob(#{term_id}) Root"
24
+ b.context = local_context
25
+ b.on(:success, "#{self.class.to_s}.batch_finished") unless options[:mark_synced] == false
26
+ end
27
+ end
28
+ else
29
+ JobBatches::ConcurrentBatchJob.make_batch(jobs, context: context)
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.batch_finished(status, opts)
35
+ ctx = JobBatches::Batch.current_context
36
+ term_id = ctx[:canvas_term_id]
37
+ CanvasSync.redis.set(last_sync_key(term_id), ctx[:batch_start_time])
38
+ end
39
+
40
+ def self.last_sync_key(term_id)
41
+ ctx = JobBatches::Batch.current_context
42
+ "#{CanvasSync.redis_prefix}:#{ctx[:batch_genre]}:#{term_id}:last_sync"
43
+ end
44
+
45
+ def get_term_id(term)
46
+ term.try(:canvas_id) || term.canvas_term_id
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,29 +1,25 @@
1
- # <%= autogenerated_event_warning %>
2
-
3
- module LiveEvents
1
+ module CanvasSync::LiveEvents
4
2
  class RetryLiveEventJob < StandardError; end
5
3
 
6
- class BaseEvent < CanvasSync::Job
4
+ # Deprecated
5
+ class BaseHandler < CanvasSync::Job
7
6
  attr_accessor :raw_payload
8
7
  attr_accessor :payload
9
8
  attr_accessor :metadata
10
9
 
11
10
  def perform(event_payload)
12
11
  @raw_payload = event_payload
13
- @metadata = HashWithIndifferentAccess.new(event_payload["attributes"])
12
+ @metadata = HashWithIndifferentAccess.new(event_payload["metadata"])
14
13
  @payload = HashWithIndifferentAccess.new(event_payload["body"])
15
14
  process_with_retry
16
15
  end
17
16
 
17
+ protected
18
+
18
19
  def process
19
20
  raise "process must be implemented in your subclass"
20
21
  end
21
22
 
22
- # Live events will use a canvas global ID (cross shard) for any ID's provided. This method will return the local ID.
23
- def local_canvas_id(id)
24
- id.to_i % 10_000_000_000_000
25
- end
26
-
27
23
  private
28
24
 
29
25
  # Sometimes a creation and update event get sent by Canvas at almost the exact same time. This means
@@ -0,0 +1,26 @@
1
+
2
+ module CanvasSync::LiveEvents
3
+ class ProcessEventJob < ::CanvasSync::Job
4
+ def perform(event)
5
+ event = event.with_indifferent_access
6
+
7
+ # Support Legacy-Style Event Handlers
8
+ begin
9
+ legacy_handler = "LiveEvents::#{event['metadata']['event_name'].camelcase}Event".constantize
10
+ legacy_handler.perform_later(event)
11
+ return
12
+ rescue LoadError, NameError => e
13
+ Rails.logger.error("Error accessing legacy-style LiveEvents handler #{e}, #{event}")
14
+ end
15
+
16
+ handlers = CanvasSync::LiveEvents.registered_handlers
17
+ handlers.each do |h|
18
+ h.call(event)
19
+ rescue => e
20
+ throw e if Rails.env.test?
21
+ Rails.logger.error("LiveEvent Handler raised Error: #{e}")
22
+ Raven.captureException(e) if defined? Raven
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require_relative './live_events/base_handler.rb'
2
+ require_relative './live_events/process_event_job.rb'
3
+
4
+ module CanvasSync
5
+ module LiveEvents
6
+
7
+ @@registered_handlers = []
8
+
9
+ class << self
10
+ def listen(event_types = nil, &blk)
11
+ if event_types != nil
12
+ blk = wrap_method(blk) do |inner, event|
13
+ meta = event[:metadata]
14
+ payload = event[:payload]
15
+
16
+ if event_types.include?(meta[:event_name])
17
+ inner.call(*args)
18
+ end
19
+ end
20
+ end
21
+
22
+ @@registered_handlers << blk
23
+ end
24
+
25
+ def registered_handlers
26
+ @@registered_handlers
27
+ end
28
+
29
+ private
30
+
31
+ def wrap_method(inner, &outer)
32
+ ->(*args) {
33
+ outer.call(inner, *args)
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,63 @@
1
+ require 'active_record'
2
+
3
+ module CanvasSync
4
+ module MiscHelper
5
+ MigrationClass = Rails.version < '5.0' ? ActiveRecord::Migration : ActiveRecord::Migration[4.2]
6
+
7
+ def self.to_boolean(v)
8
+ if Rails.version < '5.0'
9
+ ActiveRecord::Type::Boolean.new.type_cast_from_user(v)
10
+ else
11
+ ActiveRecord::Type::Boolean.new.deserialize(v)
12
+ end
13
+ end
14
+
15
+ def self.invoke_task(job)
16
+ job = job.symbolize_keys
17
+
18
+ job_args = job[:args] || job[:parameters] || []
19
+ job_kwargs = job[:kwargs] || {}
20
+
21
+ if (mthd = job[:method]) && !(job[:class] || job[:instance_of] || job[:model])
22
+ if mthd.include?('#')
23
+ clazz, method = clazz.split("#")
24
+ job[:instance_of] = clazz
25
+ job[:method] = method
26
+ elsif mthd.include?('.')
27
+ clazz, method = mthd.split(".")
28
+ job[:class] = clazz
29
+ job[:method] = method
30
+ end
31
+ end
32
+
33
+ if job[:model]
34
+ # TODO Support globalid
35
+ model_class = load_constant(job[:model])
36
+ find_by = job[:find_by]
37
+ target = find_by.is_a?(Hash) ? model_class.find_by(find_by) : model_class.find_by(id: find_by)
38
+ target.send(job[:method], *job_args, **job_kwargs)
39
+ elsif job[:class]
40
+ target = load_constant(job[:class])
41
+ target.send(job[:method], *job_args, **job_kwargs)
42
+ elsif job[:instance_of]
43
+ target = load_constant(job[:instance_of]).new
44
+ target.send(job[:method], *job_args, **job_kwargs)
45
+ elsif job[:job]
46
+ job_class = load_constant(job[:job])
47
+ job_class = job_class.set(job[:options]) if job[:options].present?
48
+ if job_class < ActiveJob::Base
49
+ job_class.perform_later(*job_args, **job_kwargs)
50
+ else
51
+ job_args << job_kwargs.symbolize_keys if job_kwargs
52
+ # job_args[-1] = job_args[-1].symbolize_keys if job_args[-1].is_a?(Hash)
53
+ job_class.perform_async(*job_args)
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.load_constant(const)
59
+ const = const.constantize if const.is_a?(String)
60
+ const
61
+ end
62
+ end
63
+ end
@@ -8,16 +8,11 @@ module CanvasSync
8
8
  # @param options [Hash]
9
9
  class AssignmentGroupsProcessor < ReportProcessor
10
10
  def self.process(report_file_path, _options, report_id)
11
- new(report_file_path)
11
+ new(report_file_path, _options)
12
12
  end
13
13
 
14
- def initialize(report_file_path)
15
- CanvasSync::Importers::BulkImporter.import(
16
- report_file_path,
17
- mapping[:assignment_groups][:report_columns],
18
- AssignmentGroup,
19
- mapping[:assignment_groups][:conflict_target].to_sym,
20
- )
14
+ def initialize(report_file_path, options)
15
+ do_bulk_import(report_file_path, AssignmentGroup, options: options)
21
16
  end
22
17
  end
23
18
  end
@@ -8,16 +8,11 @@ module CanvasSync
8
8
  # @param options [Hash]
9
9
  class AssignmentsProcessor < ReportProcessor
10
10
  def self.process(report_file_path, _options, report_id)
11
- new(report_file_path)
11
+ new(report_file_path, _options)
12
12
  end
13
13
 
14
- def initialize(report_file_path)
15
- CanvasSync::Importers::BulkImporter.import(
16
- report_file_path,
17
- mapping[:assignments][:report_columns],
18
- Assignment,
19
- mapping[:assignments][:conflict_target].to_sym,
20
- )
14
+ def initialize(report_file_path, options)
15
+ do_bulk_import(report_file_path, Assignment, options: options)
21
16
  end
22
17
  end
23
18
  end
@@ -0,0 +1,19 @@
1
+ require_relative "./report_processor"
2
+
3
+ module CanvasSync
4
+ module Processors
5
+ # Processes a content migrations report using the bulk importer.
6
+ #
7
+ # @param report_file_path [String]
8
+ # @param options [Hash]
9
+ class ContentMigrationsProcessor < ReportProcessor
10
+ def self.process(report_file_path, _options, report_id)
11
+ new(report_file_path, _options)
12
+ end
13
+
14
+ def initialize(report_file_path, options)
15
+ do_bulk_import(report_file_path, ContentMigration, options: options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -8,16 +8,11 @@ module CanvasSync
8
8
  # @param options [Hash]
9
9
  class ContextModuleItemsProcessor < ReportProcessor
10
10
  def self.process(report_file_path, _options, report_id)
11
- new(report_file_path)
11
+ new(report_file_path, _options)
12
12
  end
13
13
 
14
- def initialize(report_file_path)
15
- CanvasSync::Importers::BulkImporter.import(
16
- report_file_path,
17
- mapping[:context_module_items][:report_columns],
18
- ContextModuleItem,
19
- mapping[:context_module_items][:conflict_target].to_sym,
20
- )
14
+ def initialize(report_file_path, options)
15
+ do_bulk_import(report_file_path, ContextModuleItem, options: options)
21
16
  end
22
17
  end
23
18
  end
@@ -8,16 +8,11 @@ module CanvasSync
8
8
  # @param options [Hash]
9
9
  class ContextModulesProcessor < ReportProcessor
10
10
  def self.process(report_file_path, _options, report_id)
11
- new(report_file_path)
11
+ new(report_file_path, _options)
12
12
  end
13
13
 
14
- def initialize(report_file_path)
15
- CanvasSync::Importers::BulkImporter.import(
16
- report_file_path,
17
- mapping[:context_modules][:report_columns],
18
- ContextModule,
19
- mapping[:context_modules][:conflict_target].to_sym,
20
- )
14
+ def initialize(report_file_path, options)
15
+ do_bulk_import(report_file_path, ContextModule, options: options)
21
16
  end
22
17
  end
23
18
  end