ansible: make key_from_kwargs() 10x faster

It was half the cost of the service call
This commit is contained in:
David Wilson 2018-04-27 10:38:33 +01:00
parent 79c2d6c289
commit 95039eea11
1 changed files with 13 additions and 4 deletions

View File

@ -38,6 +38,7 @@ when a child has completed a job.
"""
from __future__ import absolute_import
import hashlib
import logging
import os
import os.path
@ -114,11 +115,19 @@ class ContextService(mitogen.service.Service):
def key_from_kwargs(self, **kwargs):
"""
Generate a deduplication key from the request. The default
implementation returns a string based on a stable representation of the
input dictionary generated by :py:func:`pprint.pformat`.
Generate a deduplication key from the request.
"""
return pprint.pformat(kwargs)
out = []
stack = [kwargs]
while stack:
obj = stack.pop()
if isinstance(obj, dict):
stack.extend(sorted(obj.iteritems()))
elif isinstance(obj, (list, tuple)):
stack.extend(obj)
else:
out.append(str(obj))
return ''.join(out)
def _produce_response(self, key, response):
"""