Skip to content

add requeueing in background#12

Open
mesher-x wants to merge 11 commits into
QratorLabs:masterfrom
mesher-x:requeueing
Open

add requeueing in background#12
mesher-x wants to merge 11 commits into
QratorLabs:masterfrom
mesher-x:requeueing

Conversation

@mesher-x

Copy link
Copy Markdown

No description provided.

Comment thread aioredisqueue/queue.py Outdated
Comment thread aioredisqueue/queue.py
Comment thread aioredisqueue/queue.py Outdated
Comment thread aioredisqueue/queue.py Outdated
Comment thread aioredisqueue/queue.py Outdated
@code-of-kpp

Copy link
Copy Markdown
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
Copy Markdown
Contributor

#12

@mesher-x mesher-x changed the title (WIP) add requeueing in background add requeueing in background May 15, 2019
Comment thread aioredisqueue/queue.py Outdated
Comment thread test/test_requeueing.py
@code-of-kpp

Copy link
Copy Markdown
Contributor

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

Comment thread README.md
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
Copy Markdown
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 No newline at end of file

Copy link
Copy Markdown
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

Comment thread aioredisqueue/queue.py

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

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

Copy link
Copy Markdown
Contributor

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)

Comment thread aioredisqueue/queue.py
)

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

Copy link
Copy Markdown
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

Comment thread aioredisqueue/queue.py
)

def stop(self):
if self._is_stopped:

Copy link
Copy Markdown
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)

Comment thread aioredisqueue/queue.py

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

Copy link
Copy Markdown
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?).

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

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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