Sha256: 1c1a7126dd5de0d93f12c4488eb4fcfc49c4e1ee822fb8af4a382225b9934541

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

require 'open-uri'

module CanvasSync
  module Jobs
    # ActiveJob class that wraps around a report processor. This job will
    # download the report, and then pass the file path and options into the
    # process method on the processor.
    class ReportProcessorJob < CanvasSync::Job
      # @param job_chain [Hash]
      # @param report_name [Hash] e.g., 'provisioning_csv'
      # @param report_url [String]
      # @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_url, processor, options)
        download(report_name, report_url) do |file_path|
          options = options.merge({
            legacy_support: job_chain[:global_options][:legacy_support],
            account_id: job_chain[:global_options][:account_id]
          })
          processor.constantize.process(file_path, options)
        end

        CanvasSync.invoke_next(job_chain)
      end

      private

      def download(report_name, report_url)
        Dir.mktmpdir do |dir|
          file_path = "#{dir}/#{report_name}"
          IO.copy_stream(open(report_url), file_path)
          yield file_path
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
canvas_sync-0.3.0 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.2.4 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.2.3 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.2.2 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.2.1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.2.0 lib/canvas_sync/jobs/report_processor_job.rb