Sha256: 0f5ccddb8e4f6207cd359c32851bb8a8e78bc710ff1a7d1f8b62549e778fd59f

Contents?: true

Size: 1.52 KB

Versions: 5

Compression:

Stored size: 1.52 KB

Contents

require 'pageflow/panorama/validation'

module Pageflow
  module Panorama
    class UnpackPackageJob < ActiveJob::Base
      queue_as :slow

      include StateMachineJob

      def perform_with_result(package, _options)
        JobStatusAttributes.handle(package, stage: :unpacking) do |&progress|
          Archive.for(package) do |archive|
            parse(package, archive)
            unpack_to_s3(package, archive, &progress)
          end
        end

        :ok
      rescue Panorama::Validation::Error
        :error
      end

      private_class_method

      def unpack_to_s3(package, archive, &progress)
        bucket = Panorama.bucket_factory.from_attachment(package.attachment_on_s3)

        UnpackToS3
          .new(archive: archive,
               destination_bucket: bucket,
               destination_base_path: package.unpack_base_path,
               content_type_mapping: Panorama.config.content_type_mapping)
          .upload(&progress)
      end

      def parse(package, archive)
        result = Validation.parse(archive)

        package.index_document = result.index_document
        process_thumbnail(package, archive.find_entry(result.thumbnail))
      end

      def process_thumbnail(package, thumbnail_file)
        package.thumbnail = thumbnail_file
        package.valid?

        if package.errors.include?(:thumbnail)
          package.thumbnail = nil
          raise(Panorama::Validation::Error
                .new('pageflow.panorama.validation.unprocessable_thumbnail'))
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pageflow-panorama-2.4.0 app/jobs/pageflow/panorama/unpack_package_job.rb
pageflow-panorama-2.3.0 app/jobs/pageflow/panorama/unpack_package_job.rb
pageflow-panorama-2.2.0 app/jobs/pageflow/panorama/unpack_package_job.rb
pageflow-panorama-2.1.0 app/jobs/pageflow/panorama/unpack_package_job.rb
pageflow-panorama-2.0.0 app/jobs/pageflow/panorama/unpack_package_job.rb