Sha256: ae2516dbc8e0e7f4252598b03ede3e50b45c8d07c42f443f9d5802c51a5dbcfc

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

module CanvasSync
  module Jobs
    class SyncTermsJob < CanvasSync::Job
      # Syncs Terms using the Canvas API
      #
      # Terms are pre-synced so that provisioning reports can be scoped to term.
      #
      # @param options [Hash]
      def perform(options)
        CanvasSync.get_canvas_sync_client(batch_context).terms("self").all_pages!.each do |term_params|
          if account_id = 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, account_id)
            else
              term_params[:account_id] |= 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

      protected

      def get_term_id(term)
        term.try(:canvas_id) || term.canvas_term_id
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
canvas_sync-0.17.0.beta2 lib/canvas_sync/jobs/sync_terms_job.rb
canvas_sync-0.17.0.beta1 lib/canvas_sync/jobs/sync_terms_job.rb