mirror of
https://github.com/internetee/registry.git
synced 2025-06-08 05:34:46 +02:00
Fix async que job calling
This commit is contained in:
parent
187ce318a2
commit
1d6040cd5b
3 changed files with 17 additions and 11 deletions
|
@ -1,21 +1,26 @@
|
|||
class SendEInvoiceJob < Que::Job
|
||||
def run(invoice)
|
||||
destroy if invoice.do_not_send_e_invoice?
|
||||
def run(invoice_id)
|
||||
invoice = run_condition(Invoice.find_by(id: invoice_id))
|
||||
|
||||
invoice.to_e_invoice.deliver
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||
log_success(invoice)
|
||||
destroy
|
||||
end
|
||||
rescue Exception => e
|
||||
rescue StandardError => e
|
||||
log_error(invoice: invoice, error: e)
|
||||
raise e
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def run_condition(invoice)
|
||||
destroy unless invoice
|
||||
destroy if invoice.do_not_send_e_invoice?
|
||||
invoice
|
||||
end
|
||||
|
||||
def log_success(invoice)
|
||||
id = invoice.try(:id) || invoice
|
||||
message = "E-Invoice for an invoice with ID # #{id} was sent successfully"
|
||||
|
@ -26,8 +31,8 @@ class SendEInvoiceJob < Que::Job
|
|||
id = invoice.try(:id) || invoice
|
||||
message = <<~TEXT.squish
|
||||
There was an error sending e-invoice for invoice with ID # #{id}.
|
||||
The error message was the following: #{error}.
|
||||
This job will retry
|
||||
The error message was the following: #{error}
|
||||
This job will retry.
|
||||
TEXT
|
||||
logger.error message
|
||||
end
|
||||
|
|
|
@ -99,8 +99,7 @@ class Registrar < ApplicationRecord
|
|||
}
|
||||
]
|
||||
)
|
||||
|
||||
SendEInvoiceJob.enqueue(invoice)
|
||||
SendEInvoiceJob.enqueue(invoice.id)
|
||||
|
||||
invoice
|
||||
end
|
||||
|
|
|
@ -13,8 +13,9 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase
|
|||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
assert_nothing_raised do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
SendEInvoiceJob.enqueue(@invoice.id)
|
||||
end
|
||||
@invoice.reload
|
||||
|
||||
assert_not @invoice.e_invoice_sent_at.blank?
|
||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
|
@ -28,7 +29,7 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase
|
|||
stub_request(:get, "https://testfinance.post.ee/finance/erp/erpServices.wsdl").to_timeout
|
||||
|
||||
assert_raise HTTPClient::TimeoutError do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
SendEInvoiceJob.enqueue(@invoice.id)
|
||||
end
|
||||
assert @invoicee_invoice_sent_at.blank?
|
||||
|
||||
|
@ -36,8 +37,9 @@ class SendEInvoiceJobTest < ActiveSupport::TestCase
|
|||
EInvoice::Providers::TestProvider.deliveries.clear
|
||||
|
||||
assert_nothing_raised do
|
||||
SendEInvoiceJob.enqueue(@invoice)
|
||||
SendEInvoiceJob.enqueue(@invoice.id)
|
||||
end
|
||||
@invoice.reload
|
||||
|
||||
assert_not @invoice.e_invoice_sent_at.blank?
|
||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue