Merge "[Optimise] Use ThredGroup to manage periodic tasks"
This commit is contained in:
commit
d955928947
|
@ -24,7 +24,6 @@ import random
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
import oslo_messaging as messaging
|
import oslo_messaging as messaging
|
||||||
from oslo_service import loopingcall
|
|
||||||
from oslo_service import service
|
from oslo_service import service
|
||||||
from oslo_service import wsgi
|
from oslo_service import wsgi
|
||||||
from oslo_utils import importutils
|
from oslo_utils import importutils
|
||||||
|
@ -125,10 +124,10 @@ class Service(service.Service):
|
||||||
self.periodic_interval = periodic_interval
|
self.periodic_interval = periodic_interval
|
||||||
self.periodic_fuzzy_delay = periodic_fuzzy_delay
|
self.periodic_fuzzy_delay = periodic_fuzzy_delay
|
||||||
self.saved_args, self.saved_kwargs = args, kwargs
|
self.saved_args, self.saved_kwargs = args, kwargs
|
||||||
self.timers = []
|
|
||||||
self.coordinator = coordination
|
self.coordinator = coordination
|
||||||
|
|
||||||
setup_profiler(binary, host)
|
setup_profiler(binary, host)
|
||||||
|
self.rpcserver = None
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
version_string = version.version_string()
|
version_string = version.version_string()
|
||||||
|
@ -160,10 +159,8 @@ class Service(service.Service):
|
||||||
self.manager.init_host_with_rpc()
|
self.manager.init_host_with_rpc()
|
||||||
|
|
||||||
if self.report_interval:
|
if self.report_interval:
|
||||||
pulse = loopingcall.FixedIntervalLoopingCall(self.report_state)
|
self.tg.add_timer(self.report_interval, self.report_state,
|
||||||
pulse.start(interval=self.report_interval,
|
initial_delay=self.report_interval)
|
||||||
initial_delay=self.report_interval)
|
|
||||||
self.timers.append(pulse)
|
|
||||||
|
|
||||||
if self.periodic_interval:
|
if self.periodic_interval:
|
||||||
if self.periodic_fuzzy_delay:
|
if self.periodic_fuzzy_delay:
|
||||||
|
@ -171,11 +168,8 @@ class Service(service.Service):
|
||||||
else:
|
else:
|
||||||
initial_delay = None
|
initial_delay = None
|
||||||
|
|
||||||
periodic = loopingcall.FixedIntervalLoopingCall(
|
self.tg.add_timer(self.periodic_interval, self.periodic_tasks,
|
||||||
self.periodic_tasks)
|
initial_delay=initial_delay)
|
||||||
periodic.start(interval=self.periodic_interval,
|
|
||||||
initial_delay=initial_delay)
|
|
||||||
self.timers.append(periodic)
|
|
||||||
|
|
||||||
def _create_service_ref(self, context):
|
def _create_service_ref(self, context):
|
||||||
service_args = {
|
service_args = {
|
||||||
|
@ -247,11 +241,7 @@ class Service(service.Service):
|
||||||
self.rpcserver.stop()
|
self.rpcserver.stop()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
for x in self.timers:
|
|
||||||
try:
|
|
||||||
x.stop()
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
if self.coordinator:
|
if self.coordinator:
|
||||||
try:
|
try:
|
||||||
coordination.LOCK_COORDINATOR.stop()
|
coordination.LOCK_COORDINATOR.stop()
|
||||||
|
@ -259,16 +249,12 @@ class Service(service.Service):
|
||||||
LOG.exception("Unable to stop the Tooz Locking "
|
LOG.exception("Unable to stop the Tooz Locking "
|
||||||
"Coordinator.")
|
"Coordinator.")
|
||||||
|
|
||||||
self.timers = []
|
super(Service, self).stop(graceful=True)
|
||||||
|
|
||||||
super(Service, self).stop()
|
|
||||||
|
|
||||||
def wait(self):
|
def wait(self):
|
||||||
for x in self.timers:
|
if self.rpcserver:
|
||||||
try:
|
self.rpcserver.wait()
|
||||||
x.wait()
|
super(Service, self).wait()
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def periodic_tasks(self, raise_on_error=False):
|
def periodic_tasks(self, raise_on_error=False):
|
||||||
"""Tasks to be run at a periodic interval."""
|
"""Tasks to be run at a periodic interval."""
|
||||||
|
|
Loading…
Reference in New Issue