This repository has been archived by the owner on Mar 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mimic pluggability of other backends
- Loading branch information
Showing
10 changed files
with
149 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,24 +1,19 @@ | ||
from pyramid.threadlocal import get_current_registry | ||
from cliquet import logger | ||
|
||
|
||
class ListenerBase(object): | ||
def _done(self, name, res_id, success, result): | ||
def __init__(self, *args, **kwargs): | ||
pass | ||
|
||
def _async_run(self, event): | ||
workers = get_current_registry().workers | ||
workers.apply_async('event', self._run, (event,), self._done) | ||
|
||
def _run(self, event): | ||
raise NotImplementedError() | ||
|
||
def __call__(self, event, async=True): | ||
def __call__(self, event): | ||
""" | ||
:param event: Incoming event | ||
:param async: Run asynchronously, default: True | ||
""" | ||
if async: | ||
return self._async_run(event) | ||
else: | ||
# not used yet | ||
return self._run(event) # pragma: no cover | ||
raise NotImplementedError() | ||
|
||
def done(self, name, res_id, success, result): | ||
logger.info("Async listener done.", | ||
name=name, | ||
result_id=res_id, | ||
success=success, | ||
result=result) |
This file contains 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 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 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 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 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,20 @@ | ||
class WorkersBase(object): | ||
"""Background workers abstraction used by event listeners. | ||
""" | ||
def apply_async(self, name, func, args=None, callback=None): | ||
"""Run the specified `func` in background with the specified `args` | ||
and calls `callback` with the result. | ||
:param str name: an arbitrary identifier | ||
:param func func: a function to run in background | ||
:param tuple args: a list of parameters to provide to `func` | ||
:param func callback: the function to be called when task is done. | ||
""" | ||
raise NotImplementedError() | ||
|
||
|
||
def heartbeat(backend): | ||
"""No-op heartbeat check for workers. | ||
XXX: find out a way to provide heartbeat feature. | ||
""" | ||
return lambda r: True |
This file contains 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 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