-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(job): support debouncing (#2760)
- Loading branch information
1 parent
f6d29fc
commit 603befe
Showing
13 changed files
with
292 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--[[ | ||
Function to debounce a job. | ||
]] | ||
|
||
local function debounceJob(prefixKey, debounceId, ttl, jobId, debounceKey, token) | ||
if debounceId ~= "" then | ||
local debounceKeyExists | ||
if ttl ~= "" then | ||
debounceKeyExists = not rcall('SET', debounceKey, jobId, 'PX', ttl, 'NX') | ||
else | ||
debounceKeyExists = not rcall('SET', debounceKey, jobId, 'NX') | ||
end | ||
if debounceKeyExists then | ||
local currentDebounceJobId = rcall('GET', debounceKey) | ||
rcall("PUBLISH", prefixKey .. "debounced@" .. token, currentDebounceJobId) | ||
|
||
return currentDebounceJobId | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
--[[ | ||
Function to remove debounce key. | ||
]] | ||
|
||
local function removeDebounceKey(prefixKey, jobKey) | ||
local debounceId = rcall("HGET", jobKey, "deid") | ||
if debounceId then | ||
local debounceKey = prefixKey .. "de:" .. debounceId | ||
rcall("DEL", debounceKey) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--[[ | ||
Function to remove debounce key if needed. | ||
]] | ||
|
||
local function removeDebounceKeyIfNeeded(prefixKey, debounceId) | ||
if debounceId then | ||
local debounceKey = prefixKey .. "de:" .. debounceId | ||
local pttl = rcall("PTTL", debounceKey) | ||
|
||
if pttl == 0 or pttl == -1 then | ||
rcall("DEL", debounceKey) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.