implement the cache purger

This commit is contained in:
Kyle Drake 2015-07-02 14:23:22 -07:00
parent 4bfaa32431
commit 3a6ca6c12b
5 changed files with 67 additions and 28 deletions

View file

@ -2,21 +2,22 @@ class PurgeCacheWorker
include Sidekiq::Worker
sidekiq_options queue: :purgecache, retry: 10, backtrace: true
def perform(subdomain, path)
res = Dnsruby::Resolver.new
def perform(payload)
# :nocov:
attempt = 0
begin
attempt += 1
$pubsub_pool.with do |redis|
redis.publish 'purgecache', payload.to_json
end
rescue Redis::BaseConnectionError => error
raise if attempt > 3
puts "pubsub error: #{error}, retrying in 1s"
sleep 1
retry
if ENV['RACK_ENV'] == 'test'
proxy_ips = ['10.0.0.1', '10.0.0.2']
else
proxy_ips = res.query($config['cache_purge_ips_uri']).answer.collect {|a| a.address.to_s}
end
proxy_ips.each do |proxy_ip|
url = "http://#{proxy_ip}/:cache/purge#{path}"
begin
RestClient.get(url, host: "#{subdomain}.neocities.org")
rescue RestClient::ResourceNotFound
end
end
# :nocov:
end
end
end