Skip to content

Commit

Permalink
Make log_batches() being called internally (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
iivanou authored Feb 15, 2021
1 parent 6c9cb90 commit 29200b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
27 changes: 10 additions & 17 deletions reportportal_client/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def finish_launch(self, end_time, status=None, attributes=None, **kwargs):
"""
# process log batches firstly:
if self._batch_logs:
self.log_batch([], force=True)
self._log_batch(None, force=True)
if attributes and isinstance(attributes, dict):
attributes = _dict_to_payload(attributes)
data = {
Expand Down Expand Up @@ -463,14 +463,14 @@ def log(self, time, message, level=None, attachment=None, item_id=None):
data["itemUuid"] = item_id
if attachment:
data["attachment"] = attachment
return self.log_batch([data], item_id=item_id)
return self._log_batch(data)

def log_batch(self, log_data, item_id=None, force=False):
def _log_batch(self, log_data, force=False):
"""
Log batch of messages with attachment.
Args:
log_data: list of log records.
log_data: log record that needs to be processed.
log record is a dict of;
time, message, level, attachment
attachment is a dict of:
Expand All @@ -481,21 +481,17 @@ def log_batch(self, log_data, item_id=None, force=False):
force: Flag that forces client to process all the logs
stored in self._batch_logs immediately
"""
self._batch_logs += log_data
if log_data:
self._batch_logs.append(log_data)

if len(self._batch_logs) < self.log_batch_size and not force:
return
url = uri_join(self.base_url_v2, "log")

url = uri_join(self.base_url_v2, "log")
attachments = []
for log_item in self._batch_logs:
if item_id:
log_item["itemUuid"] = item_id
log_item["launchUuid"] = self.launch_id
attachment = log_item.get("attachment", None)

if "attachment" in log_item:
del log_item["attachment"]

attachment = log_item.pop("attachment", None)
if attachment:
if not isinstance(attachment, Mapping):
attachment = {"data": attachment}
Expand Down Expand Up @@ -523,12 +519,9 @@ def log_batch(self, log_data, item_id=None, force=False):
files=files,
verify=self.verify_ssl
)
logger.debug("log_batch - ID: %s", item_id)
logger.debug("log_batch response: %s", r.text)
self._batch_logs = []
return _get_data(r)
except KeyError:
if i < POST_LOGBATCH_RETRY_COUNT - 1:
continue
else:
if i + 1 == POST_LOGBATCH_RETRY_COUNT:
raise
2 changes: 1 addition & 1 deletion reportportal_client/static/defines.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
limitations under the License.
"""

import enum
import aenum as enum


RP_LOG_LEVELS = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup, find_packages

__version__ = '5.0.8'
__version__ = '5.0.9'

with open('requirements.txt') as f:
requirements = f.read().splitlines()
Expand Down

0 comments on commit 29200b0

Please sign in to comment.