Fix integrity checker error message, add task to warm products cache

This commit is contained in:
Rohan Mitchell
2016-02-26 13:04:55 +11:00
parent d89e9620ac
commit 21ce7ab30a
2 changed files with 23 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ require 'open_food_network/products_renderer'
ProductsCacheIntegrityCheckerJob = Struct.new(:distributor_id, :order_cycle_id) do
def perform
if diff.any?
Bugsnag.notify RuntimeError.new("Products JSON differs from cached version for distributor: #{@distributor_id}, order cycle: #{@order_cycle_id}"), diff: diff.to_s(:text)
Bugsnag.notify RuntimeError.new("Products JSON differs from cached version for distributor: #{distributor_id}, order cycle: #{order_cycle_id}"), diff: diff.to_s(:text)
end
end

View File

@@ -1,16 +1,29 @@
namespace :openfoodnetwork do
namespace :cache do
desc 'check the integrity of the products cache'
task :check_products_cache_integrity => :environment do
exchanges = Exchange.
outgoing.
joins(:order_cycle).
merge(OrderCycle.dated).
merge(OrderCycle.not_closed)
exchanges.each do |exchange|
Delayed::Job.enqueue ProductsCacheIntegrityCheckerJob.new(exchange.receiver, exchange.order_cycle), priority: 20
task :check_products_integrity => :environment do
active_exchanges.each do |exchange|
Delayed::Job.enqueue ProductsCacheIntegrityCheckerJob.new(exchange.receiver_id, exchange.order_cycle_id), priority: 20
end
end
desc 'warm the products cache'
task :warm_products => :environment do
active_exchanges.each do |exchange|
Delayed::Job.enqueue RefreshProductsCacheJob.new(exchange.receiver_id, exchange.order_cycle_id), priority: 10
end
end
private
def active_exchanges
Exchange.
outgoing.
joins(:order_cycle).
merge(OrderCycle.dated).
merge(OrderCycle.not_closed)
end
end
end