Skip to content

Commit 3abebb0

Browse files
romanRoman Plevka
roman
authored and
Roman Plevka
committed
addresses #39 - retry POSTing logs if KeyError occurs on iterating over env variables
1 parent db85677 commit 3abebb0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

reportportal_client/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
ReportPortalService,
2121
ReportPortalServiceAsync,
2222
)
23+
24+
POST_LOGBATCH_RETRY_COUNT = 10

reportportal_client/service.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import logging
2121

2222
from .errors import ResponseError, EntryCreatedError, OperationCompletionError
23+
from reportportal_client import POST_LOGBATCH_RETRY_COUNT
2324

2425
logger = logging.getLogger(__name__)
2526
logger.addHandler(logging.NullHandler())
@@ -291,7 +292,20 @@ def log_batch(self, log_data):
291292
)
292293
)]
293294
files.extend(attachments)
294-
r = self.session.post(url=url, files=files, verify=self.verify_ssl)
295+
for i in range(POST_LOGBATCH_RETRY_COUNT):
296+
try:
297+
r = self.session.post(
298+
url=url,
299+
files=files,
300+
verify=self.verify_ssl
301+
)
302+
except KeyError:
303+
if i < POST_LOGBATCH_RETRY_COUNT - 1:
304+
continue
305+
else:
306+
raise
307+
break
308+
295309
logger.debug("log_batch - Stack: %s", self.stack)
296310
logger.debug("log_batch response: %s", r.text)
297311

0 commit comments

Comments
 (0)