Class: Lcms::Engine::DocumentGenerateGdocJob

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

Constant Summary collapse

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

Instance Method Summary collapse

Methods included from ResqueJob

included, #result_key, #store_initial_result, #store_result

Instance Method Details

#perform(document, options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/jobs/lcms/engine/document_generate_gdoc_job.rb', line 21

def perform(document, options)
  content_type = options[:content_type]
  document = DocumentGenerator.document_presenter.new document.reload, content_type: content_type
  gdoc = GDOC_EXPORTERS[content_type].new(document, options).export

  key = options[:excludes].present? ? options[:gdoc_folder] : document.gdoc_key

  document.with_lock do
    document.update links: document.reload.links.merge(key => gdoc.url)
  end

  return unless options[:bundle]

  # Re-generate all materials if full lesson has been requested
  GDOC_EXPORTERS.keys.reject { |x| x == content_type }.each do |type|
    GDOC_EXPORTERS[type].new(document, options).export
  end
end