Skip to content

Commit 0252e92

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent fe6832e commit 0252e92

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

UnleashClient/__init__.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
from UnleashClient.api import register_client
1818
from UnleashClient.constants import (
19+
APPLICATION_HEADERS,
1920
DISABLED_VARIATION,
2021
ETAG,
2122
METRIC_LAST_SENT_TIME,
2223
REQUEST_RETRIES,
2324
REQUEST_TIMEOUT,
2425
SDK_NAME,
2526
SDK_VERSION,
26-
APPLICATION_HEADERS,
2727
)
2828
from UnleashClient.events import (
2929
BaseEvent,
@@ -312,10 +312,21 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
312312
)
313313

314314
# Decide mode
315-
mode = (self.experimental_mode or {}).get("type") if self.experimental_mode else None
316-
format_mode = (self.experimental_mode or {}).get("format") if self.experimental_mode else None
315+
mode = (
316+
(self.experimental_mode or {}).get("type")
317+
if self.experimental_mode
318+
else None
319+
)
320+
format_mode = (
321+
(self.experimental_mode or {}).get("format")
322+
if self.experimental_mode
323+
else None
324+
)
317325

318-
if fetch_toggles and (mode is None or (mode == "polling" and (format_mode in (None, "full")))):
326+
if fetch_toggles and (
327+
mode is None
328+
or (mode == "polling" and (format_mode in (None, "full")))
329+
):
319330
# Default/full polling
320331
fetch_headers = {
321332
**base_headers,
@@ -348,8 +359,8 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
348359
executor=self.unleash_executor_name,
349360
kwargs=job_args,
350361
)
351-
elif fetch_toggles and mode == "streaming": # Streaming mode
352-
362+
elif fetch_toggles and mode == "streaming": # Streaming mode
363+
353364
stream_headers = {
354365
**base_headers,
355366
"unleash-interval": self.unleash_refresh_interval_str_millis,
@@ -367,7 +378,7 @@ def initialize_client(self, fetch_toggles: bool = True) -> None:
367378

368379
# Start metrics job only
369380
self.unleash_scheduler.start()
370-
else: # No fetching - only load from cache
381+
else: # No fetching - only load from cache
371382
job_args = {
372383
"cache": self.cache,
373384
"engine": self.engine,

UnleashClient/streaming/manager.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
from ld_eventsource import SSEClient
77
from ld_eventsource.config import ConnectStrategy
8+
from yggdrasil_engine.engine import UnleashEngine
89

910
from UnleashClient.constants import STREAMING_URL
1011
from UnleashClient.utils import LOGGER
11-
from yggdrasil_engine.engine import UnleashEngine
1212

1313

1414
class StreamingManager:
@@ -55,7 +55,9 @@ def start(self):
5555
if self._thread and self._thread.is_alive():
5656
return
5757
self._stop.clear()
58-
self._thread = threading.Thread(target=self._run, name="UnleashStreaming", daemon=True)
58+
self._thread = threading.Thread(
59+
target=self._run, name="UnleashStreaming", daemon=True
60+
)
5961
self._thread.start()
6062

6163
def stop(self):
@@ -115,7 +117,9 @@ def _run(self):
115117
LOGGER.debug("Ignoring SSE event type: %s", event.event)
116118

117119
# Heartbeat timeout: trigger reconnect via SSEClient interrupt (uses internal retry)
118-
if self._hb_timeout and (time.time() - last_event_time > self._hb_timeout):
120+
if self._hb_timeout and (
121+
time.time() - last_event_time > self._hb_timeout
122+
):
119123
LOGGER.warning("Heartbeat timeout exceeded; reconnecting")
120124
try:
121125
client.interrupt()

0 commit comments

Comments
 (0)