mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-27 21:06:49 +00:00
Removes use of #handle_asynchronously, which we need to do elsewhere. Fixes:
BulkInvoiceService#start_pdf_job starts a background process to create a pdf with multiple invoices
Failure/Error:
expect do
service.start_pdf_job [1, 2]
end.to enqueue_job Delayed::PerformableMethod
expected to enqueue exactly 1 jobs, but enqueued 0
# ./spec/services/bulk_invoice_service_spec.rb:8:in `block (3 levels) in <top (required)>'
35 lines
565 B
Ruby
35 lines
565 B
Ruby
class BulkInvoiceService
|
|
attr_reader :id
|
|
|
|
def initialize
|
|
@id = new_invoice_id
|
|
end
|
|
|
|
def start_pdf_job(order_ids)
|
|
BulkInvoiceJob.perform_later order_ids, "#{file_directory}/#{@id}.pdf"
|
|
end
|
|
|
|
def invoice_created?(invoice_id)
|
|
File.exist? filepath(invoice_id)
|
|
end
|
|
|
|
def filepath(invoice_id)
|
|
"#{directory}/#{invoice_id}.pdf"
|
|
end
|
|
|
|
private
|
|
|
|
def new_invoice_id
|
|
Time.zone.now.to_i.to_s
|
|
end
|
|
|
|
def directory
|
|
'tmp/invoices'
|
|
end
|
|
|
|
def file_directory
|
|
Dir.mkdir(directory) unless File.exist?(directory)
|
|
directory
|
|
end
|
|
end
|