Sha256: 1a879f7ee875ec29fa44a6a9ed831581f80ad8920b12f5fc2a135566c4bb25d3

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module CanvasSync
  module Jobs
    # ActiveJob class that starts a Canvas provisioning report
    class SyncProvisioningReportJob < CanvasSync::Job
      # @param job_chain [Hash]
      # @param 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.
      def perform(job_chain, options)
        if options[:term_scope]
          Term.send(options[:term_scope]).find_each do |term|
            # Deep copy the job_chain so each report gets the correct term id passed into
            # its options with no side effects
            term_id = get_term_id(term)
            duped_job_chain = Marshal.load(Marshal.dump(job_chain))
            duped_job_chain[:global_options][:canvas_term_id] = term_id
            start_report(report_params(options, term_id), duped_job_chain, options)
          end
        else
          start_report(report_params(options), job_chain, options)
        end
      end

      private

      def start_report(report_params, job_chain, options)
        CanvasSync::Jobs::ReportStarter.perform_later(
          job_chain,
          "proservices_provisioning_csv",
          report_params,
          CanvasSync::Processors::ProvisioningReportProcessor.to_s,
          options,
        )
      end

      def report_params(options, canvas_term_id=nil)
        params = {
          include_deleted: true,
        }

        options[:models].each do |model|
          params[model] = true
        end

        params[:enrollment_term_id] = canvas_term_id if canvas_term_id

        params.merge!(options[:report_parameters]) if options[:report_parameters].present?

        { parameters: params }
      end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
canvas_sync-0.10.4 lib/canvas_sync/jobs/sync_provisioning_report_job.rb