Commit 1777b8f4 authored by David Wilson's avatar David Wilson

ansible: use DeduplicatingService for ContextService; closes #162.

parent f6b5d9f2
...@@ -30,7 +30,7 @@ from __future__ import absolute_import ...@@ -30,7 +30,7 @@ from __future__ import absolute_import
import mitogen.service import mitogen.service
class ContextService(mitogen.service.Service): class ContextService(mitogen.service.DeduplicatingService):
""" """
Used by worker processes connecting back into the top-level process to Used by worker processes connecting back into the top-level process to
fetch the single Context instance corresponding to the supplied connection fetch the single Context instance corresponding to the supplied connection
...@@ -60,20 +60,11 @@ class ContextService(mitogen.service.Service): ...@@ -60,20 +60,11 @@ class ContextService(mitogen.service.Service):
""" """
handle = 500 handle = 500
max_message_size = 1000 max_message_size = 1000
required_args = {
'method': str
}
def __init__(self, router): def get_response(self, args):
super(ContextService, self).__init__(router) args.pop('discriminator', None)
self._context_by_key = {} method = getattr(self.router, args.pop('method'))
return method(**args)
def validate_args(self, args):
return isinstance(args, dict)
def dispatch(self, dct, msg):
key = repr(sorted(dct.items()))
dct.pop('discriminator', None)
if key not in self._context_by_key:
method = getattr(self.router, dct.pop('method'))
self._context_by_key[key] = method(**dct)
return self._context_by_key[key]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment