mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
Raise error if record not found, and don't retry too many times
After 10 minutes, I'd consider that it failed to open the order cycle. Who would want their products to sync, or get a notification at a random time during the order cycle? Best viewed with whitespace ignored.
This commit is contained in:
@@ -4,13 +4,14 @@
|
||||
#
|
||||
# Currently, an order cycle is considered open in the shopfront when orders_open_at >= now.
|
||||
# But now there are some pre-conditions for opening an order cycle, so we would like to change that.
|
||||
# Instead, the presence of opened_at (and absence of closed_at) should indicate it is open.
|
||||
# Instead, the presence of opened_at (and absence of processed_at) should indicate it is open.
|
||||
class OpenOrderCycleJob < ApplicationJob
|
||||
sidekiq_options retry_for: 10.minutes
|
||||
|
||||
def perform(order_cycle_id)
|
||||
ActiveRecord::Base.transaction do
|
||||
# Fetch order cycle if it's still unopened, and lock DB row until finished
|
||||
order_cycle = OrderCycle.lock.find_by(id: order_cycle_id, opened_at: nil)
|
||||
return if order_cycle.nil?
|
||||
order_cycle = OrderCycle.lock.find_by!(id: order_cycle_id, opened_at: nil)
|
||||
|
||||
sync_remote_variants(order_cycle)
|
||||
|
||||
|
||||
@@ -89,7 +89,13 @@ RSpec.describe OpenOrderCycleJob do
|
||||
|
||||
# Resume and complete both jobs:
|
||||
breakpoint.unlock
|
||||
threads.each(&:join)
|
||||
|
||||
# Join each thread to the main thread to ensure they end.
|
||||
# Any exceptions that were raised, are raised to the main thread.
|
||||
# We're expecting RecordNotFound because the record was locked by the first concurrent thread.
|
||||
expect{
|
||||
threads.each(&:join)
|
||||
}.to raise_error ActiveRecord::RecordNotFound
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user