Skip to content

Instantly share code, notes, and snippets.

@linko
Created March 10, 2014 09:50
Show Gist options
  • Save linko/9462187 to your computer and use it in GitHub Desktop.
Save linko/9462187 to your computer and use it in GitHub Desktop.
class ElementCacheWorker
include Sidekiq::Worker
include Rails.application.routes.url_helpers
sidekiq_options retry: true, failures: true
def perform(element_id)
element = Element.where(id: element_id).first
if element.present?
breakouts_to_expire = element.subtree.map(&:breakouts).flatten.compact.uniq
breakouts_to_expire.each do |breakout|
ActionController::Base.new.expire_fragment(breakout.to_cache_fragment)
ActionController::Base.new.expire_fragment(breakout.to_cache_fragment_for_subscriber)
alignment_report = breakout.alignment_report
product = alignment_report.product
ActionController::Base.new.expire_fragment(subscriber_product_alignment_report_url(product, alignment_report, host: AppConfig['host']).split(%r{://}).last)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment