diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index bef39599..136ac512 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -6,4 +6,11 @@ class ApplicationJob < ActiveJob::Base # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError + queue_as :default + + rescue_from(StandardError) do |exception| + Sentry.capture_message(exception) + end + + retry_on StandardError, wait: :exponentially_longer, attempts: 5 end diff --git a/app/jobs/bling_order_item_creator_base_job.rb b/app/jobs/bling_order_item_creator_base_job.rb index 0fbebbbe..5741f2ed 100644 --- a/app/jobs/bling_order_item_creator_base_job.rb +++ b/app/jobs/bling_order_item_creator_base_job.rb @@ -1,12 +1,6 @@ # frozen_string_literal: true class BlingOrderItemCreatorBaseJob < ApplicationJob - queue_as :default - rescue_from(StandardError) do |exception| - Sentry.capture_message(exception) - end - - retry_on StandardError, wait: :exponentially_longer, attempts: 5 attr_accessor :account_id, :alteration_date diff --git a/app/jobs/order_items_job.rb b/app/jobs/order_items_job.rb index 639edc11..eaceec4a 100644 --- a/app/jobs/order_items_job.rb +++ b/app/jobs/order_items_job.rb @@ -1,14 +1,11 @@ class OrderItemsJob < ApplicationJob - queue_as :default - retry_on StandardError, attempts: 5, wait: :exponentially_longer + queue_as :items def perform(record) - return unless record.items.empty? - account_id = record.account_id items_attributes = [] order = Services::Bling::FindOrder.call(id: record.bling_order_id, order_command: 'find_order', tenant: account_id) - raise StandardError if order['error'].present? + raise(StandardError, order['error']) if order['error'].present? order['data']['itens'].each do |item| items_attributes << { diff --git a/app/models/bling_order_item.rb b/app/models/bling_order_item.rb index 53e6db6d..2ae9a1d4 100644 --- a/app/models/bling_order_item.rb +++ b/app/models/bling_order_item.rb @@ -133,6 +133,8 @@ def value end def synchronize_items + return unless items.empty? + OrderItemsJob.perform_later(self) end end