mirror of
https://github.com/neocities/neocities.git
synced 2025-04-28 11:12:30 +02:00
use redis connection pool for cache purge
This commit is contained in:
parent
adaf581731
commit
c0bea57468
2 changed files with 6 additions and 2 deletions
|
@ -51,7 +51,9 @@ Sidekiq.configure_client do |config|
|
||||||
end
|
end
|
||||||
|
|
||||||
if $config['pubsub_url']
|
if $config['pubsub_url']
|
||||||
$pubsub = Redis.new url: $config['pubsub_url']
|
$pubsub_pool = ConnectionPool.new(size: 10, timeout: 5) {
|
||||||
|
Redis.new url: $config['pubsub_url']
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if $config['pubsub_url'].nil? && ENV['RACK_ENV'] == 'production'
|
if $config['pubsub_url'].nil? && ENV['RACK_ENV'] == 'production'
|
||||||
|
|
|
@ -6,7 +6,9 @@ class PurgeCacheWorker
|
||||||
attempt = 0
|
attempt = 0
|
||||||
begin
|
begin
|
||||||
attempt += 1
|
attempt += 1
|
||||||
$pubsub.publish 'purgecache', payload.to_json
|
$pubsub_pool.with do |redis|
|
||||||
|
redis.publish 'purgecache', payload.to_json
|
||||||
|
end
|
||||||
rescue Redis::BaseConnectionError => error
|
rescue Redis::BaseConnectionError => error
|
||||||
raise if attempt > 3
|
raise if attempt > 3
|
||||||
puts "pubsub error: #{error}, retrying in 1s"
|
puts "pubsub error: #{error}, retrying in 1s"
|
||||||
|
|
Loading…
Add table
Reference in a new issue