diff --git a/golem/client.py b/golem/client.py index 569544fd76..cc76bfded6 100644 --- a/golem/client.py +++ b/golem/client.py @@ -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): diff --git a/tests/golem/test_client.py b/tests/golem/test_client.py index d8dc8c9fb0..e5f5d8c153 100644 --- a/tests/golem/test_client.py +++ b/tests/golem/test_client.py @@ -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()