Fix Redis delayed message promotion#852
Closed
iamdinhthuan wants to merge 1 commit into
Closed
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #431.
Redis delayed messages were promoted by enqueueing a copy to the canonical queue and then acking the original delay-queue message as two separate operations. If the original delay message was requeued before the ack completed, the same logical message could be promoted more than once.
This PR adds a Redis-specific consumer hook that promotes due delayed messages atomically in the Redis Lua dispatch script. The generic worker path still falls back to the existing enqueue-then-ack behavior for consumers that do not implement the hook.
Verification:
.venv/bin/python -m pytest tests/test_worker.py::test_delayed_messages_use_consumer_promotion_hook tests/test_redis.py::test_redis_consumer_promotes_delayed_messages_atomically -q.venv/bin/python -m pytest tests/test_redis.py tests/test_worker.py -qwith Redis 7 running locally via Docker:23 passed in 66.07s.venv/bin/python -m black --check dramatiq/broker.py dramatiq/worker.py dramatiq/brokers/redis.py tests/test_worker.py tests/test_redis.py.venv/bin/python -m isort -c dramatiq/broker.py dramatiq/worker.py dramatiq/brokers/redis.py tests/test_worker.py tests/test_redis.py.venv/bin/python -m flake8 dramatiq/broker.py dramatiq/worker.py dramatiq/brokers/redis.py tests/test_worker.py tests/test_redis.py.venv/bin/python -m mypy dramatiq/broker.py dramatiq/worker.py dramatiq/brokers/redis.py tests/test_worker.py tests/test_redis.py