Commit 9fa2e150 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Improve logging for workerpool tasks by providing __repr__



Before it would log something like “starting task
(<ganeti.http.client._HttpClientPendingRequest object at 0x2aaaad176790>,)”,
which isn't really useful for debugging. Now it'll log “[…]
<ganeti.http.client._HttpClientPendingRequest
req=<ganeti.http.client.HttpClientRequest 172.24.x.y:1811 PUT /node_info at
0x2aaaaab7ed10> at 0x2aaaaab823d0>”.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 02fc74da
......@@ -95,6 +95,14 @@ class HttpClientRequest(object):
self.resp_headers = None
self.resp_body = None
def __repr__(self):
status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__),
"%s:%s" % (self.host, self.port),
self.method,
self.path]
return "<%s at %#x>" % (" ".join(status), id(self))
class _HttpClientToServerMessageWriter(http.HttpMessageWriter):
pass
......@@ -328,6 +336,12 @@ class _HttpClientPendingRequest(object):
# Thread synchronization
self.done = threading.Event()
def __repr__(self):
status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__),
"req=%r" % self.request]
return "<%s at %#x>" % (" ".join(status), id(self))
class HttpClientWorker(workerpool.BaseWorker):
"""HTTP client worker class.
......
......@@ -190,6 +190,13 @@ class _QueuedJob(object):
# Condition to wait for changes
self.change = threading.Condition(self.queue._lock)
def __repr__(self):
status = ["%s.%s" % (self.__class__.__module__, self.__class__.__name__),
"id=%s" % self.id,
"ops=%s" % ",".join([op.input.Summary() for op in self.ops])]
return "<%s at %#x>" % (" ".join(status), id(self))
@classmethod
def Restore(cls, queue, state):
"""Restore a _QueuedJob from serialized state:
......
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