Class: PdfMage::Workers::UploadFile

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_mage/workers/upload_file.rb

Overview

A Sidekiq job that uploads a rendered PDF to Amazon S3.

Since:

  • 0.1.0

Constant Summary

Constants inherited from Base

Base::STRIP_STRING_OPTIONS

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(pdf_id, callback_url = nil, meta = nil) ⇒ Object

Since:

  • 0.1.0



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/pdf_mage/workers/upload_file.rb', line 12

def perform(pdf_id, callback_url = nil, meta = nil)
  validate_aws_config!

  s3 = Aws::S3::Resource.new(
    access_key_id: CONFIG.,
    region: CONFIG.,
    secret_access_key: CONFIG.
  )

  obj = s3.bucket(CONFIG.).object(pdf_id)
  obj.upload_file(pdf_filename(pdf_id))
  pdf_url = obj.presigned_url(:get, expires_in: CONFIG.aws_presigned_url_duration)

  `rm #{pdf_filename(pdf_id)}` if CONFIG.delete_file_on_upload
  PdfMage::Workers::SendWebhook.perform_async(pdf_url, callback_url, meta) if string_exists?(callback_url)
end