mirror of
https://github.com/neocities/neocities.git
synced 2025-05-15 17:07:19 +02:00
purge for delete and purge for refreshing
This commit is contained in:
parent
12a543d2aa
commit
985a2f8b60
7 changed files with 184 additions and 3 deletions
23
workers/delete_cache_order_worker.rb
Normal file
23
workers/delete_cache_order_worker.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class DeleteCacheOrderWorker
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :deletecacheorder, retry: 1000, backtrace: true, average_scheduled_poll_interval: 1
|
||||
|
||||
sidekiq_retry_in do |count|
|
||||
return 10 if count < 10
|
||||
180
|
||||
end
|
||||
|
||||
RESOLVER = Dnsruby::Resolver.new
|
||||
|
||||
def perform(username, path)
|
||||
if ENV['RACK_ENV'] == 'test'
|
||||
proxy_ips = ['10.0.0.1', '10.0.0.2']
|
||||
else
|
||||
proxy_ips = RESOLVER.query($config['cache_purge_ips_uri']).answer.collect {|a| a.address.to_s}
|
||||
end
|
||||
|
||||
proxy_ips.each do |proxy_ip|
|
||||
DeleteCacheWorker.perform_async proxy_ip, username, path
|
||||
end
|
||||
end
|
||||
end
|
34
workers/delete_cache_worker.rb
Normal file
34
workers/delete_cache_worker.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
require 'open-uri'
|
||||
|
||||
# PurgeCacheWorker refreshes the cache, this actually deletes it.
|
||||
# This is because when the file is 404ing the PurgeCacheWorker
|
||||
# will just sit on the stale cache, even though it's not supposed to.
|
||||
# It's some nginx bug. I'm not going to deal with it.
|
||||
|
||||
class DeleteCacheWorker
|
||||
HTTP_TIMEOUT = 5
|
||||
include Sidekiq::Worker
|
||||
sidekiq_options queue: :deletecache, retry: 1000, backtrace: false, average_scheduled_poll_interval: 1
|
||||
|
||||
sidekiq_retry_in do |count|
|
||||
return 10 if count < 10
|
||||
180
|
||||
end
|
||||
|
||||
def perform(proxy_ip, username, path)
|
||||
# Must always have a forward slash
|
||||
path = '/' + path if path[0] != '/'
|
||||
|
||||
url = Addressable::URI.encode_component(
|
||||
"http://#{proxy_ip}/:cache/purge#{path}",
|
||||
Addressable::URI::CharacterClasses::QUERY
|
||||
)
|
||||
begin
|
||||
RestClient::Request.execute method: :get, url: url, timeout: HTTP_TIMEOUT, headers: {
|
||||
host: URI::encode("#{username}.neocities.org")
|
||||
}
|
||||
rescue RestClient::ResourceNotFound
|
||||
rescue RestClient::Forbidden
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue