Class: Pageflow::Panorama::UnpackPackageJob

Inherits:
ActiveJob::Base
  • Object
show all
Includes:
StateMachineJob
Defined in:
app/jobs/pageflow/panorama/unpack_package_job.rb

Instance Method Summary collapse

Instance Method Details

#parse(package, archive) ⇒ Object



36
37
38
39
40
41
# File 'app/jobs/pageflow/panorama/unpack_package_job.rb', line 36

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

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

#perform_with_result(package, _options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/jobs/pageflow/panorama/unpack_package_job.rb', line 10

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

#process_thumbnail(package, thumbnail_file) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'app/jobs/pageflow/panorama/unpack_package_job.rb', line 43

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

#unpack_to_s3(package, archive, &progress) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'app/jobs/pageflow/panorama/unpack_package_job.rb', line 25

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