Add support for scheduling background push notifications

This commit is contained in:
Jon Chambers
2022-08-08 16:11:24 -04:00
committed by Jon Chambers
parent c2be0af9d9
commit 5f6b66dad6
5 changed files with 291 additions and 42 deletions

View File

@@ -0,0 +1,17 @@
local lastBackgroundNotificationTimestampKey = KEYS[1]
local queueKey = KEYS[2]
local accountDevicePair = ARGV[1]
local currentTimeMillis = tonumber(ARGV[2])
local backgroundNotificationPeriod = tonumber(ARGV[3])
local lastBackgroundNotificationTimestamp = redis.call("GET", lastBackgroundNotificationTimestampKey)
local nextNotificationTimestamp
if (lastBackgroundNotificationTimestamp) then
nextNotificationTimestamp = tonumber(lastBackgroundNotificationTimestamp) + backgroundNotificationPeriod
else
nextNotificationTimestamp = currentTimeMillis
end
redis.call("ZADD", queueKey, "NX", nextNotificationTimestamp, accountDevicePair)