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 Attribute Summary

Attributes inherited from CanvasSync::Job

#job_chain, #job_log

Instance Method Summary collapse

Methods inherited from CanvasSync::Job

#create_job_log, #report_checker_wait_time, #update_or_create_model

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
40
41
42
43
# File 'lib/canvas_sync/jobs/report_checker.rb', line 13

def perform(job_chain, report_name, report_id, processor, options) # rubocop:disable Metrics/AbcSize
   = options[:account_id] || job_chain[:global_options][:account_id] || "self"
  report_status = CanvasSync.get_canvas_sync_client(job_chain[:global_options])
                            .report_status(, 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,
      report_id,
    )
  when "error", "deleted"
    message = "Report failed to process; status was #{report_status} for report_name: #{report_name}, report_id: #{report_id}" # rubocop:disable Metrics/LineLength
    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