Module: CanvasSync
- Defined in:
- lib/canvas_sync.rb,
lib/canvas_sync/job.rb,
lib/canvas_sync/config.rb,
lib/canvas_sync/engine.rb,
lib/canvas_sync/version.rb,
lib/canvas_sync/sidekiq_job.rb,
app/models/canvas_sync/job_log.rb,
lib/canvas_sync/jobs/report_checker.rb,
lib/canvas_sync/jobs/report_starter.rb,
lib/canvas_sync/jobs/sync_roles_job.rb,
lib/canvas_sync/jobs/sync_terms_job.rb,
lib/canvas_sync/jobs/sync_users_job.rb,
lib/canvas_sync/jobs/sync_admins_job.rb,
lib/canvas_sync/importers/bulk_importer.rb,
lib/canvas_sync/importers/legacy_importer.rb,
lib/canvas_sync/jobs/report_processor_job.rb,
lib/canvas_sync/jobs/sync_assignments_job.rb,
lib/canvas_sync/jobs/sync_submissions_job.rb,
lib/canvas_sync/processors/report_processor.rb,
lib/canvas_sync/generators/install_generator.rb,
lib/canvas_sync/jobs/sync_context_modules_job.rb,
lib/canvas_sync/jobs/sync_assignment_groups_job.rb,
lib/canvas_sync/processors/assignments_processor.rb,
lib/canvas_sync/processors/submissions_processor.rb,
lib/canvas_sync/jobs/sync_provisioning_report_job.rb,
lib/canvas_sync/jobs/sync_context_module_items_job.rb,
lib/canvas_sync/processors/context_modules_processor.rb,
lib/canvas_sync/processors/assignment_groups_processor.rb,
lib/canvas_sync/generators/install_live_events_generator.rb,
lib/canvas_sync/processors/provisioning_report_processor.rb,
lib/canvas_sync/processors/context_module_items_processor.rb
Defined Under Namespace
Modules: Importers, Jobs, Processors, Sidekiq Classes: Config, Engine, InstallGenerator, InstallLiveEventsGenerator, Job, JobLog
Constant Summary collapse
- SUPPORTED_MODELS =
%w[ users courses accounts terms enrollments sections assignments submissions roles admins assignment_groups context_modules context_module_items xlist ].freeze
- SUPPORTED_LIVE_EVENTS =
%w[ course enrollment submission assignment user syllabus grade module module_item course_section ].freeze
- VERSION =
"0.6.0".freeze
Class Method Summary collapse
-
.config ⇒ Object
Returns the CanvasSync config.
-
.configure {|config| ... } ⇒ Object
Configure options for CanvasSync.
-
.default_provisioning_report_chain(models, term_scope = nil, legacy_support = false, account_id = nil) ⇒ Hash
Syncs terms, users/roles/admins if necessary, then the rest of the specified models.
-
.get_canvas_sync_client(options) ⇒ Object
Calls the canvas_sync_client in your app.
-
.invoke_next(job_chain) ⇒ Object
Invokes the next job in a chain of jobs.
-
.process_jobs(job_chain) ⇒ Object
Runs a chain of ordered jobs.
-
.provisioning_sync(models, term_scope: nil, legacy_support: false, account_id: nil) ⇒ Object
Runs a standard provisioning sync job with no extra report types.
Class Method Details
.config ⇒ Object
Returns the CanvasSync config
207 208 209 |
# File 'lib/canvas_sync.rb', line 207 def config @config ||= CanvasSync::Config.new end |
.configure {|config| ... } ⇒ Object
Configure options for CanvasSync. See config.rb for valid configuration options.
Example:
CanvasSync.configure do |config|
config.classes_to_only_log_errors_on << "Blah"
end
201 202 203 204 |
# File 'lib/canvas_sync.rb', line 201 def configure yield config config end |
.default_provisioning_report_chain(models, term_scope = nil, legacy_support = false, account_id = nil) ⇒ Hash
Syncs terms, users/roles/admins if necessary, then the rest of the specified models.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/canvas_sync.rb', line 112 def default_provisioning_report_chain(models, term_scope=nil, legacy_support=false, account_id=nil) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/LineLength term_scope = term_scope.to_s if term_scope ############################## # Pre provisioning report jobs ############################## # Always sync Terms first pre_provisioning_jobs = [{ job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }] # Users, roles, and admins are synced before provisioning because they cannot be scoped to term if models.include?("users") && term_scope.present? pre_provisioning_jobs.push(job: CanvasSync::Jobs::SyncUsersJob.to_s, options: {}) models -= ["users"] end if models.include?("roles") pre_provisioning_jobs.push(job: CanvasSync::Jobs::SyncRolesJob.to_s, options: {}) models -= ["roles"] end if models.include?("admins") pre_provisioning_jobs.push(job: CanvasSync::Jobs::SyncAdminsJob.to_s, options: {}) models -= ["admins"] end ############################### # Post provisioning report jobs ############################### post_provisioning_jobs = [] if models.include?("assignments") post_provisioning_jobs.push(job: CanvasSync::Jobs::SyncAssignmentsJob.to_s, options: {}) models -= ["assignments"] end if models.include?("submissions") post_provisioning_jobs.push(job: CanvasSync::Jobs::SyncSubmissionsJob.to_s, options: {}) models -= ["submissions"] end if models.include?("assignment_groups") post_provisioning_jobs.push(job: CanvasSync::Jobs::SyncAssignmentGroupsJob.to_s, options: {}) models -= ["assignment_groups"] end if models.include?("context_modules") post_provisioning_jobs.push(job: CanvasSync::Jobs::SyncContextModulesJob.to_s, options: {}) models -= ["context_modules"] end if models.include?("context_module_items") post_provisioning_jobs.push(job: CanvasSync::Jobs::SyncContextModuleItemsJob.to_s, options: {}) models -= ["context_module_items"] end provisioning_job = { job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: term_scope, models: models }, } jobs = pre_provisioning_jobs + Array.wrap(provisioning_job) + post_provisioning_jobs = { legacy_support: legacy_support } [:account_id] = account_id if account_id.present? { jobs: jobs, global_options: } end |
.get_canvas_sync_client(options) ⇒ Object
Calls the canvas_sync_client in your app. If you have specified an account ID when starting the job it will pass the account ID to your canvas_sync_client method.
186 187 188 189 190 191 192 |
# File 'lib/canvas_sync.rb', line 186 def get_canvas_sync_client() if [:account_id] canvas_sync_client([:account_id]) else canvas_sync_client end end |
.invoke_next(job_chain) ⇒ Object
Invokes the next job in a chain of jobs.
This should typically be called automatically by the gem where necessary.
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/canvas_sync.rb', line 89 def invoke_next(job_chain) return if job_chain[:jobs].empty? # Make sure all job classes are serialized as strings job_chain[:jobs].each { |job| job[:job] = job[:job].to_s } duped_job_chain = Marshal.load(Marshal.dump(job_chain)) jobs = duped_job_chain[:jobs] next_job = jobs.shift next_job_class = next_job[:job].constantize next_job_class.perform_later(duped_job_chain, next_job[:options]) end |
.process_jobs(job_chain) ⇒ Object
Runs a chain of ordered jobs
See the README for usage and examples
80 81 82 |
# File 'lib/canvas_sync.rb', line 80 def process_jobs(job_chain) invoke_next(job_chain) end |
.provisioning_sync(models, term_scope: nil, legacy_support: false, account_id: nil) ⇒ Object
Runs a standard provisioning sync job with no extra report types. Terms will be synced first using the API. If you are syncing users/roles/admins and have also specified a Term scope, Users/Roles/Admins will by synced first, before every other model (as Users/Roles/Admins are never scoped to Term).
70 71 72 73 |
# File 'lib/canvas_sync.rb', line 70 def provisioning_sync(models, term_scope: nil, legacy_support: false, account_id: nil) validate_models!(models) invoke_next(default_provisioning_report_chain(models, term_scope, legacy_support, account_id)) end |