Skip to content
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

add requeueing in background #12

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

mesher-x
Copy link

No description provided.

aioredisqueue/queue.py Outdated Show resolved Hide resolved
aioredisqueue/queue.py Show resolved Hide resolved
aioredisqueue/queue.py Outdated Show resolved Hide resolved
aioredisqueue/queue.py Outdated Show resolved Hide resolved
aioredisqueue/queue.py Outdated Show resolved Hide resolved
@code-of-kpp
Copy link
Contributor

Is it WIP?

@mesher-x mesher-x changed the title add requeueing in background (WIP) add requeueing in background May 3, 2019
@code-of-kpp
Copy link
Contributor

#12

@mesher-x mesher-x changed the title (WIP) add requeueing in background add requeueing in background May 15, 2019
aioredisqueue/queue.py Outdated Show resolved Hide resolved
test/test_requeueing.py Show resolved Hide resolved
@code-of-kpp
Copy link
Contributor

Also please update a README file. Ideally show some usage example there.

@@ -47,6 +47,5 @@ performed during each such call.
be renamed into `put_nowait`.
- `get_multi` and `put_multi` methods, allowing getting and putting multiple
items from queue with one call
- method for periodical requeueing of not acknowledged tasks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add at least minimal usage example



class Stopped(Exception):
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a newline

@@ -82,6 +97,9 @@ def _put_pipe(self, task_id, task_payload):
)

def put(self, task, method='lua'):
if self._is_stopped:
raise exceptions.Stopped
Copy link
Contributor

@code-of-kpp code-of-kpp May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an error: you are rising an instance of type type. (Pylint should be able to find this)

@@ -145,12 +169,18 @@ def _ack_pipe(self, task_id):
)

def _ack(self, task_id, method='multi'):
if self._is_stopped:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is excessive

return await self._redis.evalsha(
self._lua_sha['requeue'],
keys=[self._keys['ack'], self._keys['queue']],
args=[before],
)

def stop(self):
if self._is_stopped:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that one too (it is OK to call .stop() multiple times)


if self._requeue_interval != 0:
self._regular_requeue_task = \
self._loop.create_task(self._requeue_regularly())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.
Creating a task in constructor doesn't feel right. Especially if we have to call .stop() afterwords (we did't .start() or .run() anything, right?).

Copy link
Contributor

@code-of-kpp code-of-kpp May 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we call __init__ it is not guaranteed that loop is activated and redis has connection (although it wouldn't be a very popular use case).
So we have three options:

  1. start periodic task only when some other method called, requeue_interval != 0 and corresponding future is None (not really a great idea but will kind of work)
  2. Wrap everything into __aenter__ and __aexit__ so to use an instance one will have to call create it with async with. It is unclear whether we should or should not support calls outside async with block.
  3. Provide __aenter__ and __aexit__ only for periodic task. This is a little bit more flexible option for user as periodic task can be stopped and started multiple times. But it is kind of harder to implement: We need to provide separate class (asynchronous context manager which would implement those magic methods) for this particular case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the easiest way for now is to provide run_periodic() method that will have requeue_interval argument. Corresponding stop_periodic() will have obvious semantics. Your more general .stop() method will have to go to a different pull request (or to /dev/null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants