mirror of
https://github.com/neocities/neocities.git
synced 2025-08-05 17:18:02 +02:00
implement the cache purger
This commit is contained in:
parent
4bfaa32431
commit
3a6ca6c12b
5 changed files with 67 additions and 28 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue