Fix sending empty reports, issue #205

This commit is contained in:
allegroai 2020-09-09 22:09:49 +03:00
parent f4917572bb
commit 299ce14515
2 changed files with 11 additions and 9 deletions

View File

@ -314,8 +314,9 @@ class Metrics(InterfaceBase):
except Exception as ex:
warning('Failed reporting metric, line {} [{}]'.format(i, ex))
batch_requests = api_events.AddBatchRequest(requests=list_requests)
res = task.session.send(batch_requests)
if res and not res.ok():
warning("failed logging metric task to backend ({:d} lines, {})".format(
len(batch_requests.requests), str(res.meta)))
if batch_requests.requests:
res = task.session.send(batch_requests)
if res and not res.ok():
warning("failed logging metric task to backend ({:d} lines, {})".format(
len(batch_requests.requests), str(res.meta)))
return True

View File

@ -151,7 +151,7 @@ class TaskHandler(BufferingHandler):
self.__log_stderr("WARNING: trains.log - Failed logging task to backend ({:d} lines)".format(len(buffer)))
batch_requests = None
if batch_requests:
if batch_requests and batch_requests.requests:
self._pending += 1
self._add_to_queue(batch_requests)
@ -276,8 +276,9 @@ class TaskHandler(BufferingHandler):
warning('Failed reporting log, line {} [{}]'.format(i, ex))
batch_requests = events.AddBatchRequest(
requests=[events.TaskLogEvent(task=task.id, **r) for r in list_requests])
res = task.session.send(batch_requests)
if res and not res.ok():
warning("failed logging task to backend ({:d} lines, {})".format(
len(batch_requests.requests), str(res.meta)))
if batch_requests.requests:
res = task.session.send(batch_requests)
if res and not res.ok():
warning("failed logging task to backend ({:d} lines, {})".format(
len(batch_requests.requests), str(res.meta)))
return True