only send new debug data, send more often
This commit is contained in:
parent
0fbef43b71
commit
0fb3d1a65a
2 changed files with 17 additions and 10 deletions
|
@ -26,13 +26,15 @@ class Downloads(Thread):
|
|||
self.transfers = SqliteDict(self._dbpath, tablename='transfers', autocommit=False)
|
||||
|
||||
def download_updates(self):
|
||||
now = int(time.mktime(time.gmtime()))
|
||||
now = int(time.time())
|
||||
if now > settings.server.get('last_update_check', 0) + 24*60*60:
|
||||
settings.server['last_update_check'] = now
|
||||
update.download()
|
||||
state.user().export_library()
|
||||
if settings.preferences.get('sendDiagnostics'):
|
||||
if settings.preferences.get('sendDiagnostics') and \
|
||||
now > settings.server.get('last_send_diagnostics', 0) + 60*60:
|
||||
utils.send_debug()
|
||||
settings.server['last_send_diagnostics'] = now
|
||||
|
||||
def download_next(self):
|
||||
import item.models
|
||||
|
|
17
oml/utils.py
17
oml/utils.py
|
@ -495,22 +495,25 @@ def send_debug():
|
|||
'User-Agent': settings.USER_AGENT,
|
||||
}
|
||||
debug_log = os.path.join(settings.data_path, 'debug.log')
|
||||
last_debug = settings.server.get('last_debug')
|
||||
old = last_debug is not None
|
||||
try:
|
||||
if os.path.exists(debug_log):
|
||||
data = []
|
||||
today = datetime.now().strftime('%Y-%m-%d').encode()
|
||||
old = True
|
||||
with open(debug_log, 'rb') as fd:
|
||||
with open(debug_log, 'r') as fd:
|
||||
for line in fd:
|
||||
if line.startswith(today):
|
||||
t = line.split(':DEBUG')[0]
|
||||
if t.count('-') == 2:
|
||||
timestamp = t
|
||||
if old and timestamp > last_debug:
|
||||
old = False
|
||||
if not old:
|
||||
data.append(line)
|
||||
data = b'\n'.join(data)
|
||||
data = '\n'.join(data)
|
||||
if data:
|
||||
bytes_io = io.BytesIO()
|
||||
gzip_file = gzip.GzipFile(fileobj=bytes_io, mode='wb')
|
||||
gzip_file.write(data)
|
||||
gzip_file.write(data.encode())
|
||||
gzip_file.close()
|
||||
result = bytes_io.getvalue()
|
||||
bytes_io.close()
|
||||
|
@ -519,5 +522,7 @@ def send_debug():
|
|||
r = opener.open(url, result)
|
||||
if r.status != 200:
|
||||
logger.debug('failed to send debug information')
|
||||
else:
|
||||
settings.server['last_debug'] = timestamp
|
||||
except:
|
||||
logger.debug('failed to send debug information')
|
||||
|
|
Loading…
Reference in a new issue