Sha256: 7a61ed00fe371c3ba5d5a25720587a48d0133f8467d36649b6d9578629c3c14c

Contents?: true

Size: 1.2 KB

Versions: 40

Compression:

Stored size: 1.2 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 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(report_name, report_url, processor, options, report_id)
        @job_log.update_attributes(job_class: processor)
        download(report_name, report_url) do |file_path|
          options = batch_context.merge(options).merge({
            report_processor_job_id: @job_log.job_id
          })
          processor.constantize.process(file_path, options, report_id)
        end
      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

40 entries across 40 versions & 1 rubygems

Version Path
canvas_sync-0.17.15 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.14 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.13 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.12 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.10.beta2 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.10.beta1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.8 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.8.beta4 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.8.beta3 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.8.beta2 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.8.beta1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.7 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.7.beta1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.6 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.6.beta1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.5 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.5.beta2 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.5.beta1 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.4 lib/canvas_sync/jobs/report_processor_job.rb
canvas_sync-0.17.3.beta3 lib/canvas_sync/jobs/report_processor_job.rb