From ad64e8df1ccb8891fb0cec9c7fe0396c5cb769df Mon Sep 17 00:00:00 2001 From: miaohb Date: Sun, 17 Sep 2017 17:54:19 -0700 Subject: [PATCH] Avoid running periodic tasks on all workers This patch registers periodic tasks only to the main process, ensuring that they run once per instance (or group of workers). Closes-Bug: #1717548 Change-Id: Ie0038207ccdfa04d0c14c7194835c9d4c470fecc --- zun/cmd/compute.py | 1 + zun/common/rpc_service.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/zun/cmd/compute.py b/zun/cmd/compute.py index 96e3554e7..0c6df988e 100644 --- a/zun/cmd/compute.py +++ b/zun/cmd/compute.py @@ -42,4 +42,5 @@ def main(): server = rpc_service.Service.create(CONF.compute.topic, CONF.host, endpoints, binary='zun-compute') launcher = service.launch(CONF, server) + server.create_periodic_tasks() launcher.wait() diff --git a/zun/common/rpc_service.py b/zun/common/rpc_service.py index 3b6649943..ef16e7072 100644 --- a/zun/common/rpc_service.py +++ b/zun/common/rpc_service.py @@ -60,6 +60,9 @@ class Service(service.Service): profiler.setup(binary, CONF.host) def start(self): + self._server.start() + + def create_periodic_tasks(self): servicegroup.setup(CONF, self.binary, self.tg) periodic.setup(CONF, self.tg) for endpoint in self.endpoints: @@ -68,7 +71,6 @@ class Service(service.Service): periodic_interval_max=CONF.periodic_interval_max, context=context.get_admin_context(all_tenants=True) ) - self._server.start() def stop(self): if self._server: