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 = {}) ⇒ void
This method returns an undefined value.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/workers/pdf_generation_worker.rb', line 25 def perform( = {}) layout = [:layout] || {} if layout.blank? Rails.logger.error '[PdfGenerationWorker] called without a layout' return end result = GeneratedPdfGenerator.from_layout( layout: layout, title: [:title], instructions: [:instructions], created_by_id: [:created_by_id], source_publication_id: [: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 |