Class: PdfMage::Workers::RenderPdf
- Defined in:
- lib/pdf_mage/workers/render_pdf.rb
Overview
A Sidekiq job that renders a PDF using Chrome headless and kicks off post-render tasks, such as webhook processing or uploading to Amazon S3.
Constant Summary
Constants inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#ensure_directory_exists_for_pdf, #pdf_filename, #secretize_url, #string_exists?, #strip_string
Instance Method Details
#perform(website_url, callback_url = nil, filename = nil, meta = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pdf_mage/workers/render_pdf.rb', line 14 def perform(website_url, callback_url = nil, filename = nil, = nil) LOGGER.info "Rendering [#{website_url}] with callback [#{callback_url}] and meta: #{.inspect}" stripped_filename = strip_string(filename) stripped_filename_present = string_exists?(stripped_filename) # If a filename exists and the stripped version causes the string to be empty, warn about it in the logs. if filename && !stripped_filename_present LOGGER.warn "'#{filename}' is not a valid ASCII string, falling back to UUID for PDF name." end pdf_id = stripped_filename_present ? stripped_filename : SecureRandom.uuid ensure_directory_exists_for_pdf(pdf_filename(pdf_id)) url_with_secret = secretize_url(website_url) `#{CONFIG.chrome_exe} --headless --disable-gpu --print-to-pdf=#{pdf_filename(pdf_id)} #{url_with_secret}` raise "Error executing chrome PDF export. Status: [#{status}]" unless $CHILD_STATUS.zero? LOGGER.info "Rendered PDF [#{pdf_id}] with status [#{status}]" if CONFIG.aws_account_key PdfMage::Workers::UploadFile.perform_async(pdf_id, callback_url, ) elsif string_exists?(callback_url) PdfMage::Workers::SendWebhook.perform_async(pdf_filename(pdf_id), callback_url, ) end end |