Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/app/workers/workarea/bust_navigation_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def perform(id)
taxon = Navigation::Taxon.find(id)
taxon.ancestors.each(&:touch)
taxon.descendants.each(&:touch)
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
2 changes: 2 additions & 0 deletions core/app/workers/workarea/generate_promo_codes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class GeneratePromoCodes

def perform(id)
Pricing::Discount::CodeList.find(id).generate_promo_codes!
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
2 changes: 2 additions & 0 deletions core/app/workers/workarea/index_categorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def self.perform(category)
def perform(id)
category = Catalog::Category.find(id)
self.class.perform(category)
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
2 changes: 2 additions & 0 deletions core/app/workers/workarea/index_product_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class IndexProductRule
def perform(id)
product_list = Catalog::Category.find(id)
IndexCategorization.perform(product_list)
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
2 changes: 2 additions & 0 deletions core/app/workers/workarea/mark_discounts_as_redeemed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def perform(order_id)
order = Order.find(order_id)
shippings = Shipping.where(order_id: order_id).to_a
mark_redeemed(order, shippings)
rescue Mongoid::Errors::DocumentNotFound
nil
end

def mark_redeemed(order, shippings)
Expand Down
2 changes: 2 additions & 0 deletions core/app/workers/workarea/save_order_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def save_user(metrics)

def perform(order_id)
self.class.perform(Order.find(order_id))
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
2 changes: 2 additions & 0 deletions core/app/workers/workarea/save_user_order_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def perform(order_id)

save_payment_details(order, user)
save_shipping_details(order, user)
rescue Mongoid::Errors::DocumentNotFound
nil
end

def save_payment_details(order, user)
Expand Down
2 changes: 2 additions & 0 deletions core/app/workers/workarea/send_refund_email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def perform(id)
refund = Payment::Refund.find(id)
return if refund.total.zero?
Storefront::PaymentMailer.refunded(id.to_s).deliver_now
rescue Mongoid::Errors::DocumentNotFound
nil
end
end
end
5 changes: 5 additions & 0 deletions core/app/workers/workarea/synchronize_user_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def perform(id)
},
upsert: true
)
rescue Mongoid::Errors::DocumentNotFound
# Callback workers may execute after the underlying document has been
# removed (e.g. test cleanup / truncation). Missing documents should be
# treated as a no-op.
nil
end
end
end
27 changes: 26 additions & 1 deletion testing/lib/workarea/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,23 @@ module Workers
module SearchIndexing
extend ActiveSupport::Concern

def wait_for_elasticsearch!(timeout: 30)
start = Time.now

loop do
Workarea.elasticsearch.cluster.health(wait_for_status: "yellow")
break
rescue Faraday::ConnectionFailed, ::Elasticsearch::Transport::Transport::Errors::ServiceUnavailable, ::Elasticsearch::Transport::Transport::Errors::BadGateway
raise if (Time.now - start) > timeout
sleep 0.5
end
end

included do
setup do
Workarea.config.auto_refresh_search = true
WebMock.disable_net_connect!(allow_localhost: true)
wait_for_elasticsearch!
Workarea::Elasticsearch::Document.all.each(&:reset_indexes!)
Workarea::Search::Storefront.ensure_dynamic_mappings
end
Expand Down Expand Up @@ -241,9 +254,21 @@ module Setup
extend ActiveSupport::Concern
include ActiveJob::TestHelper

def truncate_all_mongoid_clients!
# Mongoid.truncate! only truncates the global (default) client.
# Workarea uses additional clients (e.g. :metrics), so ensure we clear
# data for all configured clients to avoid cross-test pollution.
Mongoid::Clients.clients.values.each do |client|
client.database.collections.each do |collection|
next if collection.name.start_with?('system.')
collection.find.delete_many
end
end
end

included do
setup do
Mongoid.truncate!
truncate_all_mongoid_clients!
Workarea.redis.flushdb
WebMock.disable_net_connect!(allow_localhost: true)
ActionMailer::Base.deliveries.clear
Expand Down
Loading