Class: CanvasSync::Jobs::ReportChecker
- Inherits:
-
CanvasSync::Job
- Object
- ActiveJob::Base
- CanvasSync::Job
- CanvasSync::Jobs::ReportChecker
- 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.
Constant Summary collapse
- REPORT_TIMEOUT =
12.hours
- COMPILATION_TIMEOUT =
1.hour
Instance Attribute Summary
Attributes inherited from CanvasSync::Job
Instance Method Summary collapse
Methods inherited from CanvasSync::Job
#create_job_log, #report_checker_wait_time, #update_or_create_model
Instance Method Details
#perform(report_name, report_id, processor, options, checker_context = {}) ⇒ nil
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/canvas_sync/jobs/report_checker.rb', line 15 def perform(report_name, report_id, processor, , checker_context = {}) # rubocop:disable Metrics/AbcSize account_id = [:account_id] || batch_context[:account_id] || "self" report_status = CanvasSync.get_canvas_sync_client(batch_context) .report_status(account_id, report_name, report_id) case report_status["status"].downcase when "complete" CanvasSync::Jobs::ReportProcessorJob.perform_later( report_name, report_status["attachment"]["url"], processor, , report_id, ) when "error", "deleted" = "Report failed to process; status was #{report_status} for report_name: #{report_name}, report_id: #{report_id}" # rubocop:disable Metrics/LineLength Rails.logger.error() raise else report_timeout = parse_timeout([:report_timeout] || batch_context[:report_timeout] || REPORT_TIMEOUT) if timeout_met?([:sync_start_time], report_timeout) raise "Report appears to be stuck #{report_name}##{report_id}" end if report_status["status"].downcase == 'compiling' checker_context['compiling_since'] ||= DateTime.now.iso8601 compilation_timeout = parse_timeout([:report_compilation_timeout] || batch_context[:report_compilation_timeout] || COMPILATION_TIMEOUT) if timeout_met?(checker_context['compiling_since'], compilation_timeout) raise "Report appears to be stuck #{report_name}##{report_id}" end end CanvasSync::Jobs::ReportChecker .set(wait: report_checker_wait_time) .perform_later( report_name, report_id, processor, , checker_context, ) end end |