Class: CanvasSync::Jobs::ReportChecker

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

Overview

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.

Instance Method Summary collapse

Methods inherited from CanvasSync::Job

#report_checker_wait_time

Instance Method Details

#perform(job_chain, report_name, report_id, processor, options) ⇒ nil

Parameters:

  • job_chain (Hash)
  • report_name (Hash) —

    e.g., 'provisioning_csv'

  • report_id (Integer)
  • processor (String) —

    a stringified report processor class name

  • options (Hash) —

    hash of options that will be passed to the job processor

Returns:

  • (nil)


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
38
39
# File 'lib/canvas_sync/jobs/report_checker.rb', line 13

def perform(job_chain, report_name, report_id, processor, options)
  report_status = CanvasSync.get_canvas_sync_client(job_chain[:global_options]).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