* First commit with iOS PN working * RPush cleanup worker + unique jobs config * Remove rpush tables from schema.rb * PR feedback * Feature flag and test for route * Tests and feature flag PushNotification ::Send * Update app/controllers/devices_controller.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Update spec/routing/devices_routes_spec.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * Update spec/services/push_notifications/send_spec.rb Co-authored-by: Michael Kohl <citizen428@dev.to> * PR feedback * Set Rpush driver and url * More PR feedback * Apply suggestions from code review Co-authored-by: Jamie Gaskins <jgaskins@gmail.com> * PR feedback from Rhymes * Don’t double render * Sure Co-authored-by: Josh Puetz <hi@joshpuetz.com> Co-authored-by: Josh Puetz <josh@dev.to> Co-authored-by: Michael Kohl <citizen428@dev.to> Co-authored-by: Jamie Gaskins <jgaskins@gmail.com>
21 lines
585 B
Ruby
21 lines
585 B
Ruby
module PushNotifications
|
|
class CleanupWorker
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: :low_priority, retry: 10
|
|
|
|
def perform
|
|
redis = Redis.new(url: ENV["REDIS_RPUSH_URL"] || ENV["REDIS_URL"])
|
|
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
|