Skip to content

Commit ef14caa

Browse files
committed
formatting
Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent 0da893f commit ef14caa

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/databricks/sql/telemetry/telemetry_client.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def __init__(
164164
):
165165
logger.debug("Initializing TelemetryClient for connection: %s", session_id_hex)
166166
self._telemetry_enabled = telemetry_enabled
167-
self._batch_size = batch_size if batch_size is not None else self.DEFAULT_BATCH_SIZE
167+
self._batch_size = (
168+
batch_size if batch_size is not None else self.DEFAULT_BATCH_SIZE
169+
)
168170
self._flush_interval_seconds = self.DEFAULT_FLUSH_INTERVAL_SECONDS
169171
self._session_id_hex = session_id_hex
170172
self._auth_provider = auth_provider
@@ -175,26 +177,30 @@ def __init__(
175177
self._host_url = host_url
176178
self._executor = executor
177179
self._flush_timer = None
178-
180+
179181
# Start the periodic flush timer
180182
self._start_flush_timer()
181183

182184
def _start_flush_timer(self):
183185
"""Start the periodic flush timer"""
184-
186+
185187
self._flush_timer = threading.Timer(
186-
self._flush_interval_seconds,
187-
self._periodic_flush
188+
self._flush_interval_seconds, self._periodic_flush
188189
)
189190
self._flush_timer.daemon = True # Don't prevent program exit
190191
self._flush_timer.start()
191-
logger.debug("Started flush timer for connection %s (interval: %d seconds)",
192-
self._session_id_hex, self._flush_interval_seconds)
192+
logger.debug(
193+
"Started flush timer for connection %s (interval: %d seconds)",
194+
self._session_id_hex,
195+
self._flush_interval_seconds,
196+
)
193197

194198
def _periodic_flush(self):
195199
"""Periodic flush callback - flushes events and reschedules the timer"""
196-
197-
logger.debug("Performing periodic flush for connection %s", self._session_id_hex)
200+
201+
logger.debug(
202+
"Performing periodic flush for connection %s", self._session_id_hex
203+
)
198204
self._flush()
199205
# Reschedule the next flush
200206
self._start_flush_timer()
@@ -208,7 +214,7 @@ def _stop_flush_timer(self):
208214

209215
def _export_event(self, event):
210216
"""Add an event to the batch queue and flush if batch is full"""
211-
217+
212218
logger.debug("Exporting event for connection %s", self._session_id_hex)
213219
with self._lock:
214220
self._events_batch.append(event)
@@ -220,7 +226,7 @@ def _export_event(self, event):
220226

221227
def _flush(self):
222228
"""Flush the current batch of events to the server"""
223-
229+
224230
with self._lock:
225231
events_to_flush = self._events_batch.copy()
226232
self._events_batch = []

tests/unit/test_telemetry.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,15 @@ def test_batch_size_flush(self, telemetry_client_setup):
186186
client = telemetry_client_setup["client"]
187187
client._flush = MagicMock()
188188

189-
for i in range(TelemetryClient._batch_size-1):
189+
batch_size = client._batch_size
190+
191+
for i in range(batch_size - 1):
190192
client._export_event(f"event-{i}")
191193

192194
client._flush.assert_not_called()
193-
assert len(client._events_batch) == TelemetryClient._batch_size-1
195+
assert len(client._events_batch) == batch_size - 1
194196

195-
client._export_event(f"event-{TelemetryClient._batch_size - 1}")
197+
client._export_event(f"event-{batch_size - 1}")
196198

197199
client._flush.assert_called_once()
198200

0 commit comments

Comments
 (0)