Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(service): minor fix on the dump_interval
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Oct 10, 2019
1 parent cd77a57 commit 73dae6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 6 additions & 2 deletions gnes/service/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions tests/test_service_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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([
Expand All @@ -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)
Expand Down

0 comments on commit 73dae6b

Please sign in to comment.