Skip to content

Commit

Permalink
deferred handler pending sorter
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Dec 1, 2023
1 parent ebe4af2 commit 5ecce85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions sharded_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ async def handle(self, *requests: DeferredRequest) -> None:
]

if len(pending):
pending = sorted(pending, key=lambda r: r.timestamp)
await self.worker.queue.register(DeferredHandler, *pending)

todo: list[tuple[str, list]] = [
Expand Down
5 changes: 5 additions & 0 deletions tests/test_deferred.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ async def test_deferred() -> None:
assert await queue.storage.length(drop_pipe) == 0
assert await queue.storage.length(deferred_pipe) == 2

append_order = await queue.storage.range(deferred_pipe, 2)

await worker.loop(2)
assert await queue.storage.length(drop_pipe) == 0
assert await queue.storage.length(deferred_pipe) == 2

timestamp_order = await queue.storage.range(deferred_pipe, 2)
assert list(reversed(append_order)) == timestamp_order

await sleep(0.01)

await worker.loop(2)
Expand Down

0 comments on commit 5ecce85

Please sign in to comment.