Method: Lcms::Engine::DocumentGenerateJob#perform

Defined in:
app/jobs/lcms/engine/document_generate_job.rb

#perform(document, check_queue: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/jobs/lcms/engine/document_generate_job.rb', line 17

def perform(document, check_queue: false)
  @document = document

  # Job has been queued from Material job
  if check_queue
    # Exit if any material is still generating
    return if materials_generating?
  elsif document.materials.any?
    # Queue all materials at the first time
    create_gdoc_folders
    return queue_materials
  end

  # If came here:
  # - all materials have been generated
  # - document doesn't have any materials at all
  #
  # So need to check if such job is already running or has been already queued.
  # And return in such case
  return if queued?

  if document.math?
    document.document_parts.default.each { |p| p.update!(content: EmbedEquations.call(p.content)) }
  end

  queue_documents
end