Skip to content

Commit 8c2351c

Browse files
committed
Minor updates to comments and iteration logic
1 parent a7c7deb commit 8c2351c

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/murfey/util/logging.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,9 @@ def _worker(self):
116116
except Empty:
117117
pass
118118

119-
# Calculate logging rate
119+
# Calculate logging rate based on past second
120120
now = time.time()
121-
self.log_times = [
122-
t for t in self.log_times if now - t <= 1.0
123-
] # Number of logs in last second
121+
self.log_times = [t for t in self.log_times if now - t <= 1.0]
124122
log_rate = len(self.log_times)
125123

126124
# Adjust batch size and flush interval
@@ -142,14 +140,14 @@ def _worker(self):
142140
self._send_batch(batch)
143141

144142
def _send_batch(self, batch: list[str]):
145-
for attempt in range(1, self.max_retry + 1):
143+
for attempt in range(0, self.max_retry):
146144
try:
147145
response = requests.post(self.endpoint_url, json=batch, timeout=5)
148146
if response.status_code == 200:
149147
return
150148
except requests.RequestException:
151149
pass
152-
time.sleep(2**attempt * 0.1) # Exponential backoff
150+
time.sleep(2 ** (attempt + 1) * 0.1) # Exponential backoff
153151

154152
def close(self):
155153
self._stop_event.set()

0 commit comments

Comments
 (0)