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

Commit

Permalink
Send evt.net.connection only when status changes (#4958)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiivan authored and shadeofblue committed Dec 3, 2019
1 parent bfbfef3 commit 269ff43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions golem/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1583,14 +1583,24 @@ def __init__(self,
interval_seconds: int) -> None:
super().__init__(interval_seconds)
self._client = client
self._last_value = self.poll()

def _run_async(self):
# Skip the async_run call and publish events in the main thread
self._run()

def _run(self):
self._client._publish(Network.evt_connection,
self._client.connection_status())
current_value = self.poll()
if current_value == self._last_value:
return
self._last_value = current_value
self._client._publish( # pylint: disable=protected-access
Network.evt_connection,
self._last_value,
)

def poll(self) -> Dict[str, Any]:
return self._client.connection_status()


class TaskArchiverService(LoopingCallService):
Expand Down
4 changes: 3 additions & 1 deletion tests/golem/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,9 @@ def setUp(self):
)

@patch('golem.client.logger')
def test_run(self, logger):
@patch('golem.client.NetworkConnectionPublisherService.poll')
def test_run(self, poll_mock, logger):
poll_mock.return_value = {'random_key': random.random()}
self.service._run()

logger.debug.assert_not_called()
Expand Down

0 comments on commit 269ff43

Please sign in to comment.