Sha256: 8fd2f61409c509b6fd0cb7516da472662f2d92d5865d081b55bd05a7a6884a3b

Contents?: true

Size: 1.05 KB

Versions: 7

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Lcms
  module Engine
    class DocumentGeneratePdfJob < Lcms::Engine::ApplicationJob
      include ResqueJob
      include RetrySimple

      queue_as :default

      PDF_EXPORTERS = {
        'full' => DocumentExporter::PDF::Document,
        'sm' => DocumentExporter::PDF::StudentMaterial,
        'tm' => DocumentExporter::PDF::TeacherMaterial
      }.freeze

      def perform(doc, options)
        content_type = options[:content_type]
        document = DocumentGenerator.document_presenter.new doc.reload, content_type: content_type
        filename = options[:filename].presence || "#{DocumentExporter::PDF::Base.s3_folder}/#{document.pdf_filename}"
        pdf = PDF_EXPORTERS[content_type].new(document, options).export
        url = S3Service.upload filename, pdf

        return if options[:excludes].present?

        key = ::DocumentExporter::PDF::Base.pdf_key options[:content_type]
        document.with_lock do
          document.update links: document.reload.links.merge(key => url)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lcms-engine-0.3.1 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.1.4 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.3.0 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.1.3 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.2.0 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.1.2 app/jobs/lcms/engine/document_generate_pdf_job.rb
lcms-engine-0.1.0 app/jobs/lcms/engine/document_generate_pdf_job.rb