Class: CanvasSync::Jobs::ReportStarter

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

Overview

Starts a Canvas report and enqueues a ReportChecker

Instance Attribute Summary

Attributes inherited from CanvasSync::Job

#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(report_name, report_params, processor, options, allow_redownloads: false) ⇒ nil

Parameters:

  • report_name (Hash)

    e.g., ‘provisioning_csv’

  • report_params (Hash)

    The Canvas report parameters

  • processor (String)

    a stringified report processor class name

  • options (Hash)

    hash of options that will be passed to the job processor

  • allow_redownloads (Boolean) (defaults to: false)

    whether you want the job_chain to cache this report, so that any later jobs in the chain will use the same generated report

Returns:

  • (nil)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/canvas_sync/jobs/report_starter.rb', line 12

def perform(report_name, report_params, processor, options, allow_redownloads: false)
   = options[:account_id] || batch_context[:account_id] || "self"
  options[:sync_start_time] = DateTime.now.utc.iso8601
  options[:report_params] = report_params
  report_id = start_report(, report_name, report_params)
  # TODO: Restore report caching support (does nayone actually use it?)
  # report_id = if allow_redownloads
  #               get_cached_report(account_id, report_name, report_params)
  #             else
  #               start_report(account_id, report_name, report_params)
  #             end

  batch = JobBatches::Batch.new
  batch.description = "CanvasSync #{report_name} Fiber"
  batch.jobs do
    CanvasSync::Jobs::ReportChecker.set(wait: report_checker_wait_time).perform_later(
      report_name,
      report_id,
      processor.to_s,
      options
    )
  end
end