-
Notifications
You must be signed in to change notification settings - Fork 4
add requeueing in background #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mesher-x
wants to merge
11
commits into
QratorLabs:master
Choose a base branch
from
mesher-x:requeueing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
69da24d
add requeueing in background
mesher-x b128d26
check last requeue timestamp separately, make requeue method public, …
mesher-x e2d444c
list loop argument last
mesher-x b7035ba
add no auto requeueing option
mesher-x 2a9bdb4
add lua script for requeue timestamp
mesher-x 069d9f9
change stop condition for auto requeueing, add a way to stop manually
mesher-x 061f998
change import order and variable names
mesher-x f3a3714
change stop semantics
mesher-x 74a7d48
cancel requeue_regularly task in stop method, stop queue in the end o…
mesher-x 862d41f
change import order
mesher-x d3734e0
remove periodical requeueing from new features section
mesher-x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import aioredis | ||
| import aioredisqueue | ||
| import asyncio | ||
| import pytest | ||
| import timeit | ||
|
|
||
code-of-kpp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @pytest.mark.asyncio | ||
| async def test_requeue_method(): | ||
| r = await aioredis.create_redis(('localhost', 6379), db=0) | ||
| q = aioredisqueue.queue.Queue(r) | ||
|
|
||
| await q.put(b'payload') | ||
| await q.get() | ||
| main_queue_len = await r.llen(q._keys['queue']) | ||
| ack_len = await r.hlen(q._keys['ack']) | ||
| assert ack_len >= 1 | ||
| await r.delete(q._keys['last_requeue']) | ||
| now = int(timeit.default_timer() * 1000) | ||
| results = await q._requeue(now) | ||
| assert len(results[1]) == ack_len | ||
| assert len(results[3]) == ack_len | ||
| assert results[2][-1] == main_queue_len + ack_len | ||
| assert int(await r.get(q._keys['last_requeue'])) == now | ||
|
|
||
| r.close() | ||
| await r.wait_closed() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_too_early(): | ||
| r = await aioredis.create_redis(('localhost', 6379), db=0) | ||
| q = aioredisqueue.queue.Queue(r) | ||
|
|
||
| now = int(timeit.default_timer() * 1000) | ||
| await r.set(q._keys['last_requeue'], now) | ||
| results = await q._requeue(now) | ||
| assert results[0] == b'error' | ||
|
|
||
| r.close() | ||
| await r.wait_closed() | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_in_background(): | ||
| r = await aioredis.create_redis(('localhost', 6379), db=0) | ||
| requeue_interval = 100 | ||
| eps = 0.01 | ||
| q = aioredisqueue.queue.Queue(r, requeue_interval=requeue_interval) | ||
|
|
||
| await r.delete(q._keys['last_requeue']) | ||
|
|
||
| await q.put(b'payload') | ||
| await asyncio.sleep(eps) | ||
| task = await q.get() | ||
|
|
||
| await asyncio.sleep(requeue_interval / 1000) | ||
| assert await r.hget(q._keys['ack'], task.id) is not None | ||
|
|
||
| await asyncio.sleep(requeue_interval / 1000) | ||
| assert await r.hget(q._keys['ack'], task.id) is None | ||
|
|
||
| r.close() | ||
| await r.wait_closed() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.