Skip to content

Commit

Permalink
deferred reqeust timestamp calculation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Nov 22, 2023
1 parent 2a7b354 commit 5e569f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sharded_queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def calculate_timestamp(cls, delta: float | int | timedelta) -> float:

timestamp: float = now.timestamp()
if not isinstance(delta, timedelta):
timestamp = delta = delta
timestamp = timestamp + delta

return timestamp

Expand Down
5 changes: 5 additions & 0 deletions tests/test_recurrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ async def stats() -> tuple[int, int, int]:
)
assert await stats() == (0, 1, 0), 'recurrent pipe contains request'

deffered_registration = datetime.now().timestamp()
await Worker(lock, queue).loop(1)
assert await stats() == (1, 1, 0), 'added defered request'
assert await lock.exists(recurrent_pipe)

[deferred] = await queue.storage.range(deferred_pipe, 1)
request = queue.serializer.deserialize(DeferredRequest, deferred)
assert request.timestamp >= deffered_registration

await lock.release(recurrent_pipe)
await Worker(lock, queue).loop(1, handler=RecurrentHandler)
assert await stats() == (1, 1, 0), 'no deffered duplicates'
Expand Down

0 comments on commit 5e569f1

Please sign in to comment.