Module: CanvasSync
- Defined in:
- lib/canvas_sync.rb,
lib/canvas_sync/job.rb,
lib/canvas_sync/engine.rb,
lib/canvas_sync/version.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_terms_job.rb,
lib/canvas_sync/jobs/sync_users_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/generators/install_generator.rb,
lib/canvas_sync/jobs/sync_provisioning_report_job.rb,
lib/canvas_sync/processors/provisioning_report_processor.rb
Defined Under Namespace
Modules: Importers, Jobs, Processors Classes: Engine, InstallGenerator, Job, JobLog
Constant Summary collapse
- SUPPORTED_MODELS =
%w(users courses terms enrollments sections)
- VERSION =
"0.2.3"
Class Method Summary collapse
-
.default_provisioning_report_chain(models, term_scope = nil, legacy_support = false, account_id = nil) ⇒ Hash
Syncs terms, users 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.
- .validate_models!(models) ⇒ Object
Class Method Details
.default_provisioning_report_chain(models, term_scope = nil, legacy_support = false, account_id = nil) ⇒ Hash
Syncs terms, users if necessary, then the rest of the specified models.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/canvas_sync.rb', line 76 def self.default_provisioning_report_chain(models, term_scope=nil, legacy_support=false, account_id=nil) term_scope = term_scope.to_s if term_scope # Always sync Terms first jobs = [{ job: CanvasSync::Jobs::SyncTermsJob.to_s, options: {} }] if models.include?('users') && term_scope.present? # Sync all users first when scoping by term, because users cannot be scoped to term jobs.push({ job: CanvasSync::Jobs::SyncUsersJob.to_s, options: {} }) models = models - ['users'] end jobs.push({ job: CanvasSync::Jobs::SyncProvisioningReportJob.to_s, options: { term_scope: term_scope, models: models } }) = { 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.
101 102 103 104 105 106 107 |
# File 'lib/canvas_sync.rb', line 101 def self.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.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/canvas_sync.rb', line 53 def self.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
44 45 46 |
# File 'lib/canvas_sync.rb', line 44 def self.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 and have also specified a Term scope, Users will by synced first, before every other model (as Users are never scoped to Term).
34 35 36 37 |
# File 'lib/canvas_sync.rb', line 34 def self.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 |
.validate_models!(models) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/canvas_sync.rb', line 111 def self.validate_models!(models) invalid = models - SUPPORTED_MODELS if invalid.length > 0 raise "Invalid model(s) specified: #{invalid.join(', ')}. Only #{SUPPORTED_MODELS.join(', ')} are supported." end end |