Class: CanvasSync::Jobs::SyncTermsJob

Inherits:
CanvasSync::Job show all
Defined in:
lib/canvas_sync/jobs/sync_terms_job.rb

Instance Attribute Summary

Attributes inherited from CanvasSync::Job

#job_log

Instance Method Summary collapse

Methods inherited from CanvasSync::Job

#create_job_log, #report_checker_wait_time, #update_or_create_model

Instance Method Details

#perform(options) ⇒ Object

Syncs Terms using the Canvas API

Terms are pre-synced so that provisioning reports can be scoped to term.

Parameters:

  • options (Hash)

    If options contains a :term_scope a seperate provisioning report will be started for each term in that scope. :models should be an array of models to sync.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/canvas_sync/jobs/sync_terms_job.rb', line 11

def perform(options)
  CanvasSync.get_canvas_sync_client(batch_context).terms("self").all_pages!.each do |term_params|
    if  = batch_context[:account_id]
      # These branches are primarily to support Legacy apps
      if Term.respond_to?(:create_or_update) && Term.method(:create_or_update).arity.abs == 2
        Term.create_or_update(term_params, )
      else
        term_params[:account_id] |= 
        update_or_create_model(Term, term_params)
      end
    else
      update_or_create_model(Term, term_params)
    end
  end

  if (jobs = options[:sub_jobs]).present?
    context = options[:context] || {}
    if options[:term_scope]
      Term.send(options[:term_scope]).find_each.map do |term|
        local_context = context.merge(canvas_term_id: get_term_id(term))
        JobBatches::ConcurrentBatchJob.perform_now(jobs, context: local_context)
      end
    else
      JobBatches::ConcurrentBatchJob.perform_now(jobs, context: context)
    end
  end
end