mirror of
https://github.com/sprockets/sprockets.mixins.correlation.git
synced 2024-11-23 11:19:53 +00:00
commit
08bfdcc23f
7 changed files with 43 additions and 10 deletions
|
@ -1,9 +1,14 @@
|
||||||
Version History
|
Version History
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
`1.0.2`_ (20-Jun-2016)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
- Add support for async prepare in superclasses of ``HandlerMixin``
|
||||||
|
|
||||||
`1.0.1`_ (31-Mar-2015)
|
`1.0.1`_ (31-Mar-2015)
|
||||||
~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
- Adds ``sprockets.mixins.correlation.HandlerMixin``
|
- Adds ``sprockets.mixins.correlation.HandlerMixin``
|
||||||
|
|
||||||
|
|
||||||
|
.. _`1.0.2`: https://github.com/sprockets/sprockets.mixins.correlation/compare/1.0.1...1.0.2
|
||||||
.. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1
|
.. _`1.0.1`: https://github.com/sprockets/sprockets.mixins.correlation/compare/0.0.0...1.0.1
|
||||||
|
|
|
@ -81,8 +81,8 @@ Relayed Correlation ID
|
||||||
.. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.correlation.svg
|
.. |Downloads| image:: https://img.shields.io/pypi/dm/sprockets.mixins.correlation.svg
|
||||||
:target: https://pypi.python.org/pypi/sprockets.mixins.correlation
|
:target: https://pypi.python.org/pypi/sprockets.mixins.correlation
|
||||||
.. |License| image:: https://pypip.in/license/sprockets.mixins.correlation/badge.svg
|
.. |License| image:: https://pypip.in/license/sprockets.mixins.correlation/badge.svg
|
||||||
:target: https://sprocketsmixinscorrelation.readthedocs.org/
|
:target: https://sprocketsmixinscorrelation.readthedocs.io/
|
||||||
.. |Documentation| image:: https://readthedocs.org/projects/sprocketsmixinscorrelation/badge
|
.. |Documentation| image:: https://readthedocs.org/projects/sprocketsmixinscorrelation/badge
|
||||||
:target: https://sprocketsmixinscorrelation.readthedocs.org/
|
:target: https://sprocketsmixinscorrelation.readthedocs.io/
|
||||||
|
|
||||||
.. _Python Package Index: https://pypi.python.org/pypi/sprockets.mixins.correlation
|
.. _Python Package Index: https://pypi.python.org/pypi/sprockets.mixins.correlation
|
||||||
|
|
|
@ -10,7 +10,7 @@ templates_path = []
|
||||||
source_suffix = '.rst'
|
source_suffix = '.rst'
|
||||||
master_doc = 'index'
|
master_doc = 'index'
|
||||||
project = 'sprockets.mixins.correlation'
|
project = 'sprockets.mixins.correlation'
|
||||||
copyright = '2015, AWeber Communications'
|
copyright = '2015-2016, AWeber Communications'
|
||||||
version = '.'.join(__version__.split('.')[0:1])
|
version = '.'.join(__version__.split('.')[0:1])
|
||||||
release = __version__
|
release = __version__
|
||||||
if len(version_info) > 3:
|
if len(version_info) > 3:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
tornado>=3.1,<4.4
|
|
@ -1,5 +1,12 @@
|
||||||
from .mixins import HandlerMixin
|
try:
|
||||||
|
from .mixins import HandlerMixin
|
||||||
|
|
||||||
|
except ImportError as error:
|
||||||
|
|
||||||
|
class HandlerMixin(object):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
raise error
|
||||||
|
|
||||||
|
|
||||||
version_info = (1, 0, 1)
|
version_info = (1, 0, 2)
|
||||||
__version__ = '.'.join(str(v) for v in version_info[:3])
|
__version__ = '.'.join(str(v) for v in version_info[:3])
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import tornado.gen
|
||||||
|
import tornado.log
|
||||||
|
|
||||||
|
if tornado.version_info[0] >= 4:
|
||||||
|
from tornado.concurrent import is_future
|
||||||
|
else:
|
||||||
|
import tornado.concurrent
|
||||||
|
|
||||||
|
def is_future(maybe_future):
|
||||||
|
return isinstance(maybe_future, tornado.concurrent.Future)
|
||||||
|
|
||||||
|
|
||||||
class HandlerMixin(object):
|
class HandlerMixin(object):
|
||||||
"""
|
"""
|
||||||
|
@ -39,11 +50,15 @@ class HandlerMixin(object):
|
||||||
self.__correlation_id = str(uuid.uuid4())
|
self.__correlation_id = str(uuid.uuid4())
|
||||||
super(HandlerMixin, self).__init__(*args, **kwargs)
|
super(HandlerMixin, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
@tornado.gen.coroutine
|
||||||
def prepare(self):
|
def prepare(self):
|
||||||
# Here we want to copy an incoming Correlation-ID header if
|
# Here we want to copy an incoming Correlation-ID header if
|
||||||
# one exists. We also want to set it in the outgoing response
|
# one exists. We also want to set it in the outgoing response
|
||||||
# which the property setter does for us.
|
# which the property setter does for us.
|
||||||
super(HandlerMixin, self).prepare()
|
maybe_future = super(HandlerMixin, self).prepare()
|
||||||
|
if is_future(maybe_future):
|
||||||
|
yield maybe_future
|
||||||
|
|
||||||
correlation_id = self.get_request_header(self.__header_name, None)
|
correlation_id = self.get_request_header(self.__header_name, None)
|
||||||
if correlation_id is not None:
|
if correlation_id is not None:
|
||||||
self.correlation_id = correlation_id
|
self.correlation_id = correlation_id
|
||||||
|
@ -98,11 +113,11 @@ def correlation_id_logger(handler):
|
||||||
is processing the client request.
|
is processing the client request.
|
||||||
"""
|
"""
|
||||||
if handler.get_status() < 400:
|
if handler.get_status() < 400:
|
||||||
log_method = log.access_log.info
|
log_method = tornado.log.access_log.info
|
||||||
elif handler.get_status() < 500:
|
elif handler.get_status() < 500:
|
||||||
log_method = log.access_log.warning
|
log_method = tornado.log.access_log.warning
|
||||||
else:
|
else:
|
||||||
log_method = log.access_log.error
|
log_method = tornado.log.access_log.error
|
||||||
request_time = 1000.0 * handler.request.request_time()
|
request_time = 1000.0 * handler.request.request_time()
|
||||||
correlation_id = getattr(handler, "correlation_id", None)
|
correlation_id = getattr(handler, "correlation_id", None)
|
||||||
if correlation_id is None:
|
if correlation_id is None:
|
||||||
|
|
7
tox.ini
7
tox.ini
|
@ -1,5 +1,5 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py27,py33,py34,pypy,pypy3,tornado31,tornado32,tornado40
|
envlist = py27,py33,py34,pypy,pypy3,tornado31,tornado32,tornado40,tornado43
|
||||||
toxworkdir = {toxinidir}/build/tox
|
toxworkdir = {toxinidir}/build/tox
|
||||||
skip_missing_intepreters = true
|
skip_missing_intepreters = true
|
||||||
|
|
||||||
|
@ -28,3 +28,8 @@ deps =
|
||||||
deps =
|
deps =
|
||||||
-rtest-requirements.txt
|
-rtest-requirements.txt
|
||||||
tornado>=4.0,<4.1
|
tornado>=4.0,<4.1
|
||||||
|
|
||||||
|
[testenv:tornado43]
|
||||||
|
deps =
|
||||||
|
-rtest-requirements.txt
|
||||||
|
tornado>=4.3,<4.4
|
||||||
|
|
Loading…
Reference in a new issue