mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-14 23:47:48 +00:00
Lazy load summarizers for standing order jobs outside of initializer
The enqueue script seems to causes delayed job to skip initialization of the job class, meaning that the summarizers were missing
This commit is contained in:
@@ -2,15 +2,6 @@ require 'open_food_network/standing_order_payment_updater'
|
||||
require 'open_food_network/standing_order_summarizer'
|
||||
|
||||
class StandingOrderConfirmJob
|
||||
attr_accessor :summarizer
|
||||
|
||||
delegate :record_order, :record_success, :record_issue, to: :summarizer
|
||||
delegate :record_and_log_error, :send_confirmation_summary_emails, to: :summarizer
|
||||
|
||||
def initialize
|
||||
@summarizer = OpenFoodNetwork::StandingOrderSummarizer.new
|
||||
end
|
||||
|
||||
def perform
|
||||
ids = proxy_orders.pluck(:id)
|
||||
proxy_orders.update_all(confirmed_at: Time.zone.now)
|
||||
@@ -24,6 +15,13 @@ class StandingOrderConfirmJob
|
||||
|
||||
private
|
||||
|
||||
delegate :record_order, :record_success, :record_issue, to: :summarizer
|
||||
delegate :record_and_log_error, :send_confirmation_summary_emails, to: :summarizer
|
||||
|
||||
def summarizer
|
||||
@summarizer ||= OpenFoodNetwork::StandingOrderSummarizer.new
|
||||
end
|
||||
|
||||
def proxy_orders
|
||||
ProxyOrder.not_canceled.where('confirmed_at IS NULL AND placed_at IS NOT NULL')
|
||||
.joins(:order_cycle).merge(recently_closed_order_cycles)
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
require 'open_food_network/standing_order_summarizer'
|
||||
|
||||
class StandingOrderPlacementJob
|
||||
attr_accessor :summarizer
|
||||
|
||||
delegate :record_order, :record_success, :record_issue, to: :summarizer
|
||||
delegate :record_and_log_error, :send_placement_summary_emails, to: :summarizer
|
||||
|
||||
def initialize
|
||||
@summarizer = OpenFoodNetwork::StandingOrderSummarizer.new
|
||||
end
|
||||
|
||||
def perform
|
||||
ids = proxy_orders.pluck(:id)
|
||||
proxy_orders.update_all(placed_at: Time.zone.now)
|
||||
@@ -23,6 +14,13 @@ class StandingOrderPlacementJob
|
||||
|
||||
private
|
||||
|
||||
delegate :record_order, :record_success, :record_issue, to: :summarizer
|
||||
delegate :record_and_log_error, :send_placement_summary_emails, to: :summarizer
|
||||
|
||||
def summarizer
|
||||
@summarizer ||= OpenFoodNetwork::StandingOrderSummarizer.new
|
||||
end
|
||||
|
||||
def proxy_orders
|
||||
# Loads proxy orders for open order cycles that have not been placed yet
|
||||
ProxyOrder.not_canceled.where(placed_at: nil)
|
||||
|
||||
Reference in New Issue
Block a user