Class: Lcms::Engine::MaterialGenerateGdocJob

Inherits:
ApplicationJob
  • Object
show all
Includes:
RetryDelayed, ResqueJob
Defined in:
app/jobs/lcms/engine/material_generate_gdoc_job.rb

Instance Method Summary collapse

Methods included from ResqueJob

included, #result_key, #store_initial_result, #store_result

Instance Method Details

#perform(material, document) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/jobs/lcms/engine/material_generate_gdoc_job.rb', line 11

def perform(material, document)
  return if material.pdf?

  material = DocumentGenerator.material_presenter.new(
    material,
    document: DocumentGenerator.document_presenter.new(document)
  )

  # Check if material is optional for current document
  options = {}.tap do |x|
    x[:prefix] = 'optional-' if material.optional_for?(document)
  end

  gdoc = DocumentExporter::Gdoc::Material.new(material, options).export

  new_links = {
    'materials' => {
      material.id.to_s => { 'gdoc' => gdoc.url }
    }
  }

  document.with_lock do
    links = document.reload.links
    document.update links: links.deep_merge(new_links)
  end

  Lcms::Engine::DocumentGenerateJob.perform_later(document, check_queue: true)
end