Class: DraftForge::ExportPdfJob

Inherits:
ActiveJob::Base
  • Object
show all
Defined in:
app/jobs/draft_forge/export_pdf_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(export_id, raw_html) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/jobs/draft_forge/export_pdf_job.rb', line 7

def perform(export_id, raw_html)
  export = Export.find(export_id)
  export.update!(status: :processing)

  tempfile = PdfRenderer.call(raw_html)

  filename = export.requested_filename.presence || "document.pdf"
  export.pdf.attach(io: tempfile, filename: filename, content_type: 'application/pdf')
  tempfile.close!
  export.update!(status: :complete)
rescue => e
  Rails.logger.error("[DraftForge] Export failed: #{e.class}: #{e.message}")
  export.update!(status: :failed) rescue nil
end