Skip to content

Commit b91f73e

Browse files
committed
fixup: incuberating feedback from pr review
Signed-off-by: Simon Schrottner <[email protected]>
1 parent e5133f6 commit b91f73e

File tree

2 files changed

+33
-31
lines changed
  • providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd

2 files changed

+33
-31
lines changed

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/config.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CacheType(Enum):
2626
DEFAULT_RESOLVER_TYPE = ResolverType.RPC
2727
DEFAULT_RETRY_BACKOFF = 1000
2828
DEFAULT_RETRY_BACKOFF_MAX = 120000
29-
DEFAULT_RETRY_GRACE_PERIOD = 5
29+
DEFAULT_RETRY_GRACE_PERIOD_SECONDS = 5
3030
DEFAULT_STREAM_DEADLINE = 600000
3131
DEFAULT_TLS = False
3232

@@ -41,7 +41,7 @@ class CacheType(Enum):
4141
ENV_VAR_RESOLVER_TYPE = "FLAGD_RESOLVER"
4242
ENV_VAR_RETRY_BACKOFF_MS = "FLAGD_RETRY_BACKOFF_MS"
4343
ENV_VAR_RETRY_BACKOFF_MAX_MS = "FLAGD_RETRY_BACKOFF_MAX_MS"
44-
ENV_VAR_RETRY_GRACE_PERIOD = "FLAGD_RETRY_GRACE_PERIOD"
44+
ENV_VAR_RETRY_GRACE_PERIOD_SECONDS = "FLAGD_RETRY_GRACE_PERIOD"
4545
ENV_VAR_STREAM_DEADLINE_MS = "FLAGD_STREAM_DEADLINE_MS"
4646
ENV_VAR_TLS = "FLAGD_TLS"
4747

@@ -118,7 +118,9 @@ def __init__( # noqa: PLR0913
118118
self.retry_grace_period: int = (
119119
int(
120120
env_or_default(
121-
ENV_VAR_RETRY_GRACE_PERIOD, DEFAULT_RETRY_GRACE_PERIOD, cast=int
121+
ENV_VAR_RETRY_GRACE_PERIOD_SECONDS,
122+
DEFAULT_RETRY_GRACE_PERIOD_SECONDS,
123+
cast=int,
122124
)
123125
)
124126
if retry_grace_period is None

providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/resolvers/grpc.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -113,37 +113,37 @@ def connect(self) -> None:
113113
)
114114

115115
def monitor(self) -> None:
116-
def state_change_callback(new_state: ChannelConnectivity) -> None:
117-
logger.debug(f"gRPC state change: {new_state}")
118-
if new_state == ChannelConnectivity.READY:
119-
if not self.thread or not self.thread.is_alive():
120-
self.thread = threading.Thread(
121-
target=self.listen,
122-
daemon=True,
123-
name="FlagdGrpcServiceWorkerThread",
124-
)
125-
self.thread.start()
126-
127-
if self.timer and self.timer.is_alive():
128-
logger.debug("gRPC error timer expired")
129-
self.timer.cancel()
130-
131-
elif new_state == ChannelConnectivity.TRANSIENT_FAILURE:
132-
# this is the failed reonnect attempt so we are going into stale
133-
self.emit_provider_stale(
134-
ProviderEventDetails(
135-
message="gRPC sync disconnected, reconnecting",
136-
)
116+
self.channel.subscribe(self._state_change_callback, try_to_connect=True)
117+
118+
def _state_change_callback(self, new_state: ChannelConnectivity) -> None:
119+
logger.debug(f"gRPC state change: {new_state}")
120+
if new_state == ChannelConnectivity.READY:
121+
if not self.thread or not self.thread.is_alive():
122+
self.thread = threading.Thread(
123+
target=self.listen,
124+
daemon=True,
125+
name="FlagdGrpcServiceWorkerThread",
137126
)
138-
self.start_time = time.time()
139-
# adding a timer, so we can emit the error event after time
140-
self.timer = threading.Timer(self.retry_grace_period, self.emit_error)
127+
self.thread.start()
141128

142-
logger.debug("gRPC error timer started")
143-
self.timer.start()
144-
self.connected = False
129+
if self.timer and self.timer.is_alive():
130+
logger.debug("gRPC error timer expired")
131+
self.timer.cancel()
145132

146-
self.channel.subscribe(state_change_callback, try_to_connect=True)
133+
elif new_state == ChannelConnectivity.TRANSIENT_FAILURE:
134+
# this is the failed reconnect attempt so we are going into stale
135+
self.emit_provider_stale(
136+
ProviderEventDetails(
137+
message="gRPC sync disconnected, reconnecting",
138+
)
139+
)
140+
self.start_time = time.time()
141+
# adding a timer, so we can emit the error event after time
142+
self.timer = threading.Timer(self.retry_grace_period, self.emit_error)
143+
144+
logger.debug("gRPC error timer started")
145+
self.timer.start()
146+
self.connected = False
147147

148148
def emit_error(self) -> None:
149149
logger.debug("gRPC error emitted")

0 commit comments

Comments
 (0)