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

Reporting graceful shutdown via status publisher #4858

Merged
merged 4 commits into from
Nov 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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