Change TaskManager from is-a to has-a thread
As a small stepping stone towards consolidating the shade/sdk/nodepool TaskManager implementations, change TaskManager from being a thread to having a thread. This should allow us to make nodepool's TaskManager inherit from sdk's TaskManager without losing our minds trying to understand how multi-inheritance works with Thread as one of the base classes. Change-Id: Ie89eb9e68e5e3f0a7a55cdd555c683631f305b8e
This commit is contained in:
parent
eb52394c8c
commit
d8407027cf
@ -62,11 +62,11 @@ class Task(object):
|
||||
self.exception(e, sys.exc_info()[2])
|
||||
|
||||
|
||||
class TaskManager(threading.Thread):
|
||||
class TaskManager(object):
|
||||
log = logging.getLogger("nodepool.TaskManager")
|
||||
|
||||
def __init__(self, client, name, rate):
|
||||
super(TaskManager, self).__init__(name=name)
|
||||
super(TaskManager, self).__init__()
|
||||
self.daemon = True
|
||||
self.queue = queue.Queue()
|
||||
self._running = True
|
||||
@ -74,14 +74,22 @@ class TaskManager(threading.Thread):
|
||||
self.rate = float(rate)
|
||||
self._client = None
|
||||
self.statsd = stats.get_client()
|
||||
self._thread = threading.Thread(name=name, target=self.run)
|
||||
self._thread.daemon = True
|
||||
|
||||
def setClient(self, client):
|
||||
self._client = client
|
||||
|
||||
def start(self):
|
||||
self._thread.start()
|
||||
|
||||
def stop(self):
|
||||
self._running = False
|
||||
self.queue.put(None)
|
||||
|
||||
def join(self):
|
||||
self._thread.join()
|
||||
|
||||
def run(self):
|
||||
last_ts = 0
|
||||
try:
|
||||
|
Loading…
x
Reference in New Issue
Block a user