Class: PdfGenerationWorker
- Inherits:
-
Object
- Object
- PdfGenerationWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/pdf_generation_worker.rb
Overview
Renders a PDF from a declarative layout and stages it as a GeneratedPdf,
pending review in the PDF studio. The async counterpart to the studio's inline
generation — used by the Sunny hand-off and (later) reconstruction.
Options (string or symbol keys):
layout [Hash] required — see Pdf::Toolkit.generate
title [String]
instructions [String] the prompt / request that produced the layout
created_by_id [Integer] Account id
source_publication_id [Integer] Item id, when generating a revision candidate
Instance Method Summary collapse
Instance Method Details
#perform(options = {}) ⇒ Object
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 44 |
# File 'app/workers/pdf_generation_worker.rb', line 18 def perform( = {}) opts = .symbolize_keys layout = opts[:layout] || {} if layout.blank? Rails.logger.error '[PdfGenerationWorker] called without a layout' return end result = GeneratedPdfGenerator.from_layout( layout: layout, title: opts[:title], instructions: opts[:instructions], created_by_id: opts[:created_by_id], source_publication_id: opts[:source_publication_id] ) if result.success? Rails.logger.info "[PdfGenerationWorker] staged GeneratedPdf #{result.generated_pdf.id}" else error = result.error Rails.logger.error "[PdfGenerationWorker] generation failed: #{error}" raise error if error.is_a?(Exception) # let Sidekiq retry with the real class/backtrace raise StandardError, error.to_s end end |