Sha256: 13dcf29a1f998afe44ea3e7d654f59f1a9b5331625e7d188d02ea61e0d6f34e4

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 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 = {
          "parameters[include_deleted]" => true
        }

        options[:models].each do |model|
          params["parameters[#{model}]"] = true
        end

        params["parameters[enrollment_term_id]"] = canvas_term_id if canvas_term_id

        params
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
canvas_sync-0.10.3 lib/canvas_sync/jobs/sync_provisioning_report_job.rb
canvas_sync-0.10.2 lib/canvas_sync/jobs/sync_provisioning_report_job.rb
canvas_sync-0.10.0 lib/canvas_sync/jobs/sync_provisioning_report_job.rb