From b091a0ed1a0e349b7d26cffca9ef6c2fb91675d0 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 7 Jun 2023 16:25:53 +0100 Subject: [PATCH] Ensure directory exists before saving pdf These directories can get wiped during deployments --- app/jobs/bulk_invoice_job.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/jobs/bulk_invoice_job.rb b/app/jobs/bulk_invoice_job.rb index 324554733d..596f241dd7 100644 --- a/app/jobs/bulk_invoice_job.rb +++ b/app/jobs/bulk_invoice_job.rb @@ -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