forked from python-arq/arq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redis Streams for immediate task delivery (python-arq#492)
- Loading branch information
1 parent
2f752e2
commit 00ea322
Showing
8 changed files
with
571 additions
and
100 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
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,48 @@ | ||
publish_delayed_job_lua = """ | ||
local delayed_queue_key = KEYS[1] | ||
local stream_key = KEYS[2] | ||
local job_message_id_key = KEYS[3] | ||
local job_id = ARGV[1] | ||
local job_message_id_expire_ms = ARGV[2] | ||
local score = redis.call('zscore', delayed_queue_key, job_id) | ||
if score == nil or score == false then | ||
return 0 | ||
end | ||
local message_id = redis.call('xadd', stream_key, '*', 'job_id', job_id, 'score', score) | ||
redis.call('set', job_message_id_key, message_id, 'px', job_message_id_expire_ms) | ||
redis.call('zrem', delayed_queue_key, job_id) | ||
return 1 | ||
""" | ||
|
||
publish_job_lua = """ | ||
local stream_key = KEYS[1] | ||
local job_message_id_key = KEYS[2] | ||
local job_id = ARGV[1] | ||
local score = ARGV[2] | ||
local job_message_id_expire_ms = ARGV[3] | ||
local message_id = redis.call('xadd', stream_key, '*', 'job_id', job_id, 'score', score) | ||
redis.call('set', job_message_id_key, message_id, 'px', job_message_id_expire_ms) | ||
return message_id | ||
""" | ||
|
||
get_job_from_stream_lua = """ | ||
local stream_key = KEYS[1] | ||
local job_message_id_key = KEYS[2] | ||
local message_id = redis.call('get', job_message_id_key) | ||
if message_id == false then | ||
return nil | ||
end | ||
local job = redis.call('xrange', stream_key, message_id, message_id) | ||
if job == nil then | ||
return nil | ||
end | ||
return job[1] | ||
""" |
Oops, something went wrong.