Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Reporting graceful shutdown via status publisher (#4858)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmazurek authored Nov 6, 2019
1 parent fcbe27c commit d45e232
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions golem/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ def graceful_shutdown(self) -> ShutdownResponse:
if self._config_desc.in_shutdown:
self.client.update_setting('in_shutdown', False)
logger.info('Turning off shutdown mode')
StatusPublisher.publish(
Component.client, 'start', Stage.post)
return ShutdownResponse.off

# is not providing nor requesting, normal shutdown
Expand All @@ -384,6 +386,8 @@ def graceful_shutdown(self) -> ShutdownResponse:
# configure in_shutdown
logger.info('Enabling shutdown mode, no more tasks can be started')
self.client.update_setting('in_shutdown', True)
StatusPublisher.publish(
Component.client, 'scheduled_shutdown', Stage.pre)

# subscribe to events

Expand Down
11 changes: 9 additions & 2 deletions tests/golem/test_opt_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from golem.core import variables
from golem.network.transport.tcpnetwork_helpers import SocketAddress
from golem.node import Node, ShutdownResponse
from golem.report import Component, Stage
from golem.testutils import TempDirFixture
from golem.tools.ci import ci_skip
from golem.tools.testwithdatabase import TestWithDatabase
Expand Down Expand Up @@ -839,7 +840,8 @@ def test_graceful_shutdown_quit(self, reactor, *_):
assert self.node._is_task_in_progress.called
assert self.node._reactor.stop.called

def test_graceful_shutdown_off(self, *_):
@patch('golem.node.StatusPublisher')
def test_graceful_shutdown_off(self, publisher, *_):
self.node_kwargs['config_desc'].in_shutdown = True

self.node = Node(**self.node_kwargs)
Expand All @@ -853,8 +855,11 @@ def test_graceful_shutdown_off(self, *_):
False)
assert self.node._is_task_in_progress.not_called
assert self.node.quit.not_called
publisher.publish.assert_called_with(
Component.client, 'start', Stage.post)

def test_graceful_shutdown_on(self, *_):
@patch('golem.node.StatusPublisher')
def test_graceful_shutdown_on(self, publisher, *_):
self.node = Node(**self.node_kwargs)
self.node.quit = Mock()
self.node.client = Mock()
Expand All @@ -866,6 +871,8 @@ def test_graceful_shutdown_on(self, *_):
True)
assert self.node.quit.not_called
assert self.node._is_task_in_progress.called
publisher.publish.assert_called_with(
Component.client, 'scheduled_shutdown', Stage.pre)

def test_try_shutdown(self, *_):
self.node = Node(**self.node_kwargs)
Expand Down

0 comments on commit d45e232

Please sign in to comment.