Skip to content

Commit

Permalink
fix: set adapter.connected = False on channel closing
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Nov 2, 2024
1 parent 36ccef5 commit b21a756
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pyzeebe/grpc_internals/zeebe_adapter_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class ZeebeAdapterBase:
def __init__(self, grpc_channel: grpc.aio.Channel, max_connection_retries: int = -1):
self._channel = grpc_channel
self._gateway_stub = GatewayStub(grpc_channel)
self.connected = True
self._connected = True
self.retrying_connection = False
self._max_connection_retries = max_connection_retries
self._current_connection_retries = 0

@property
def connected(self) -> bool:
return self._connected

def _should_retry(self) -> bool:
return self._max_connection_retries == -1 or self._current_connection_retries < self._max_connection_retries

Expand All @@ -41,6 +45,7 @@ async def _handle_grpc_error(self, grpc_error: grpc.aio.AioRpcError) -> NoReturn

async def _close(self) -> None:
try:
self._connected = False
await self._channel.close()
except Exception as exception:
logger.exception("Failed to close channel, %s exception was raised", type(exception).__name__)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/worker/job_poller_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ async def test_job_is_added_to_task_state(

class TestShouldPoll:
def test_should_poll_returns_expected_result_when_disconnected(self, job_poller: JobPoller):
job_poller.zeebe_adapter.connected = False
job_poller.zeebe_adapter._connected = False
job_poller.zeebe_adapter.retrying_connection = False

assert not job_poller.should_poll()

def test_continues_polling_when_retrying_connection(self, job_poller: JobPoller):
job_poller.zeebe_adapter.connected = False
job_poller.zeebe_adapter._connected = False
job_poller.zeebe_adapter.retrying_connection = True

assert job_poller.should_poll()
Expand Down

0 comments on commit b21a756

Please sign in to comment.