Ensure directory exists before saving pdf

These directories can get wiped during deployments
This commit is contained in:
Matt-Yorkley
2023-06-07 16:25:53 +01:00
parent 2d28a57c6f
commit b091a0ed1a

View File

@@ -13,6 +13,8 @@ class BulkInvoiceJob < ApplicationJob
pdf << CombinePDF.parse(invoice)
end
ensure_directory_exists filepath
pdf.save filepath
broadcast(filepath, options[:channel]) if options[:channel]
@@ -41,4 +43,10 @@ class BulkInvoiceJob < ApplicationJob
).
broadcast
end
def ensure_directory_exists(filepath)
return unless File.exist?(File.dirname(filepath))
FileUtils.mkdir_p(File.dirname(filepath))
end
end