Skip to content

Conversation

@mesher-x
Copy link

No description provided.

@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
@code-of-kpp
Copy link
Contributor

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

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


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)

)

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

)

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