From 73dae6bdea612d375a103627e725c5ade5865011 Mon Sep 17 00:00:00 2001 From: hanhxiao Date: Thu, 10 Oct 2019 12:07:47 +0800 Subject: [PATCH] fix(service): minor fix on the dump_interval --- gnes/service/base.py | 8 ++++++-- tests/test_service_mgr.py | 6 ------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/gnes/service/base.py b/gnes/service/base.py index 6eb809a2..5db79e9d 100644 --- a/gnes/service/base.py +++ b/gnes/service/base.py @@ -336,12 +336,14 @@ def run(self): except Exception as ex: self.logger.error(ex, exc_info=True) - def dump(self): + def dump(self, respect_dump_interval: bool = True): if (not self.args.read_only and self.args.dump_interval > 0 and self._model and self.is_model_changed.is_set() - and (time.perf_counter() - self.last_dump_time) > self.args.dump_interval): + and (respect_dump_interval + and (time.perf_counter() - self.last_dump_time) > self.args.dump_interval) + or not respect_dump_interval): self.is_model_changed.clear() self.logger.info('dumping changes to the model, %3.0fs since last the dump' % (time.perf_counter() - self.last_dump_time)) @@ -459,6 +461,8 @@ def _run(self, ctx): in_sock.close() out_sock.close() ctrl_sock.close() + # do not check dump_interval constraint as the last dump before close + self.dump(respect_dump_interval=False) self.logger.critical('terminated') def post_init(self): diff --git a/tests/test_service_mgr.py b/tests/test_service_mgr.py index 224233ae..c7af3726 100644 --- a/tests/test_service_mgr.py +++ b/tests/test_service_mgr.py @@ -97,8 +97,6 @@ def test_external_module(self): with ServiceManager(RouterService, args): pass - self.assertTrue(os.path.exists('foo_contrib_encoder.bin')) - os.remove('foo_contrib_encoder.bin') def test_override_module(self): args = set_indexer_parser().parse_args([ @@ -108,8 +106,6 @@ def test_override_module(self): with ServiceManager(IndexerService, args): pass - self.assertTrue(os.path.exists('foo_contrib_encoder.bin')) - os.remove('foo_contrib_encoder.bin') def test_override_twice_module(self): args = set_indexer_parser().parse_args([ @@ -120,8 +116,6 @@ def test_override_twice_module(self): with ServiceManager(IndexerService, args): pass - self.assertTrue(os.path.exists('foo_contrib_encoder.bin')) - os.remove('foo_contrib_encoder.bin') def test_grpc_with_pub(self): self._test_grpc_multiple_pub('thread', 1)