docbrown/app/workers/push_notifications/cleanup_worker.rb
Mac Siri 678dda8cf4
Routine Rubopcop lint fixes (#17844)
* Routine Rubopcop lint fixes

* Undo app_secrets_spec changes

* Fix broken spec
2022-06-07 10:17:16 -04:00

21 lines
634 B
Ruby

module PushNotifications
class CleanupWorker
include Sidekiq::Job
sidekiq_options queue: :low_priority, retry: 10, lock: :until_and_while_executing
def perform
redis = Redis.new(url: ENV.fetch("REDIS_RPUSH_URL") { ENV.fetch("REDIS_URL", nil) })
cursor = 0
until (cursor, keys = redis.scan(cursor, match: "rpush:notifications:*")).first.to_i.zero?
keys.each do |key|
next unless redis.ttl(key) == -1
next unless redis.type(key) == "hash"
next if redis.hget(key, "delivered").nil?
redis.expire(key, 8.hours.to_i)
end
end
end
end
end