Sha256: 3ba233c66e68296fe552cf3492857b6786e7ba0b6d83e9f9ebc366c71d0d4763

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

module CanvasSync
  module Jobs
    # ActiveJob class used to check the status of a pending Canvas report.
    # Re-enqueues itself if the report is still processing on Canvas.
    # Enqueues the ReportProcessor when the report has completed.
    class ReportChecker < ApplicationJob
      # @param job_chain [Hash]
      # @param report_name [Hash] e.g., 'provisioning_csv'
      # @param report_id [Integer]
      # @param processor [String] a stringified report processor class name
      # @param options [Hash] hash of options that will be passed to the job processor
      # @return [nil]
      def perform(job_chain, report_name, report_id, processor, options)
        report_status = canvas_sync_client.report_status('self', report_name, report_id)

        case report_status['status'].downcase
          when 'complete'
            CanvasSync::Jobs::ReportProcessorJob.perform_later(
              job_chain,
              report_name,
              report_status['attachment']['url'],
              processor,
              options
            )
          when 'error', 'deleted'
            message = "Report failed to process; status was #{report_status} for report_name: #{report_name}, report_id: #{report_id}"
            Rails.logger.error(message)
            raise message
          else
            CanvasSync::Jobs::ReportChecker.set(wait: report_checker_wait_time)
              .perform_later(
                job_chain,
                report_name,
                report_id,
                processor,
                options
              )
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
canvas_sync-0.1.4 lib/canvas_sync/jobs/report_checker.rb
canvas_sync-0.1.3 lib/canvas_sync/jobs/report_checker.rb
canvas_sync-0.1.2 lib/canvas_sync/jobs/report_checker.rb