Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions loafer/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class LoaferManager:

def __init__(self, routes, runner=None, _concurrency_limit=None, _max_threads=None):
self._concurrency_limit = _concurrency_limit
if runner is None:
if not runner:
self.runner = LoaferRunner(on_stop_callback=self.on_loop__stop, max_workers=_max_threads)
else:
self.runner = runner
Expand Down Expand Up @@ -62,7 +62,8 @@ def on_future__errors(self, future):
def on_loop__stop(self, *args, **kwargs):
logger.info('cancel dispatcher operations ...')

if hasattr(self, '_future'):
future = getattr(self, '_future', None)
if future:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I don't see any problem with readability here.

self._future.cancel()

self.dispatcher.stop()
14 changes: 5 additions & 9 deletions loafer/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,14 @@ def __str__(self):
type(self).__name__, self.name, self.provider, self.handler)

def apply_message_translator(self, message):
processed_message = {'content': message,
'metadata': {}}
if not self.message_translator:
return processed_message
return {'content': message, 'metadata': {}}

translated = self.message_translator.translate(processed_message['content'])
processed_message['metadata'].update(translated.get('metadata', {}))
processed_message['content'] = translated['content']
if not processed_message['content']:
translated = self.message_translator.translate(message)
if not translated['content']:
raise ValueError('{} failed to translate message={}'.format(self.message_translator, message))

return processed_message
return translated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This might override metadata values if we apply the translator several times. I'll check and then we can improve this on the side.


async def deliver(self, raw_message):
message = self.apply_message_translator(raw_message)
Expand All @@ -72,7 +68,7 @@ async def deliver(self, raw_message):
async def error_handler(self, exc_info, message):
logger.info('error handler process originated by message={}'.format(message))

if self._error_handler is not None:
if self._error_handler:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This one as well.

return await run_in_loop_or_executor(self._error_handler, exc_info, message)

return False
Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pytest
pytest-asyncio
pytest-cov
pytest-deadfixtures
pytest-runner
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you give me more context about this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's required on setup.py at line 91

python setup_requires=['pytest-runner'],

The IDE show an warnning Package requirement 'pytest-runner' is not satisfied.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think it's your IDE, I could not find anything in regular environments or circleci. Please revert this change.

codecov
asynctest
pre-commit