Commit d7a428c7 authored by Justin's avatar Justin

slapos/promise/plugin/util.py: Modified getJsonLogLatestTimestamp() to use...

slapos/promise/plugin/util.py: Modified getJsonLogLatestTimestamp() to use current_time instead of latest_timestamp
parent 860c6c4b
...@@ -5,7 +5,7 @@ import os ...@@ -5,7 +5,7 @@ import os
import textwrap import textwrap
from dateutil import parser as dateparser from dateutil import parser as dateparser
from datetime import datetime
from slapos.grid.promise.generic import GenericPromise from slapos.grid.promise.generic import GenericPromise
...@@ -66,16 +66,15 @@ class JSONPromise(GenericPromise): ...@@ -66,16 +66,15 @@ class JSONPromise(GenericPromise):
Get all data in the last "interval" seconds from JSON log Get all data in the last "interval" seconds from JSON log
Reads rotated logs too (XX.log, XX.log.1, XX.log.2, ...) Reads rotated logs too (XX.log, XX.log.1, XX.log.2, ...)
""" """
oldest_timestamp = None current_time = datetime.now()
data_list = [] data_list = []
for f in iter_logrotate_file_handle(self.__json_log_file, 'rb'): for f in iter_logrotate_file_handle(self.__json_log_file, 'rb'):
for line in iter_reverse_lines(f): for line in iter_reverse_lines(f):
l = json.loads(line.decode().replace("'", '"')) l = json.loads(line.decode().replace("'", '"'))
timestamp = dateparser.parse(l['time']) timestamp = dateparser.parse(l['time'])
data_list.append(l['data']) if (current_time - timestamp).total_seconds() > interval:
oldest_timestamp = oldest_timestamp or timestamp
if (oldest_timestamp - timestamp).total_seconds() > interval:
return data_list return data_list
data_list.append(l['data'])
return data_list return data_list
def getJsonLogLatestTimestamp(log): def getJsonLogLatestTimestamp(log):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment