Set redis logs entries to expire rather than to immediately delete them to make the logs archiver idempotent.
This commit is contained in:
parent
353da13b16
commit
c01de4a916
3 changed files with 11 additions and 6 deletions
|
@ -2,6 +2,11 @@ import redis
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from util.dynamic import import_class
|
from util.dynamic import import_class
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
|
||||||
|
ONE_DAY = timedelta(days=1)
|
||||||
|
|
||||||
|
|
||||||
class BuildStatusRetrievalError(Exception):
|
class BuildStatusRetrievalError(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -54,11 +59,11 @@ class RedisBuildLogs(object):
|
||||||
except redis.ConnectionError:
|
except redis.ConnectionError:
|
||||||
raise BuildStatusRetrievalError('Cannot retrieve build logs')
|
raise BuildStatusRetrievalError('Cannot retrieve build logs')
|
||||||
|
|
||||||
def delete_log_entries(self, build_id):
|
def expire_log_entries(self, build_id):
|
||||||
"""
|
"""
|
||||||
Deletes the logs and status keys completely.
|
Sets the log entry to expire in 1 day.
|
||||||
"""
|
"""
|
||||||
self._redis.delete(self._logs_key(build_id))
|
self._redis.expire(self._logs_key(build_id), ONE_DAY)
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -199,10 +199,10 @@ class TestBuildLogs(RedisBuildLogs):
|
||||||
else:
|
else:
|
||||||
return super(TestBuildLogs, self).get_status(build_id)
|
return super(TestBuildLogs, self).get_status(build_id)
|
||||||
|
|
||||||
def delete_log_entries(self, build_id):
|
def expire_log_entries(self, build_id):
|
||||||
if build_id == self.test_build_id:
|
if build_id == self.test_build_id:
|
||||||
return
|
return
|
||||||
if not self.allow_delegate:
|
if not self.allow_delegate:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return super(TestBuildLogs, self).delete_log_entries(build_id)
|
return super(TestBuildLogs, self).expire_log_entries(build_id)
|
||||||
|
|
|
@ -44,7 +44,7 @@ def archive_redis_buildlogs():
|
||||||
to_archive.logs_archived = True
|
to_archive.logs_archived = True
|
||||||
to_archive.save()
|
to_archive.save()
|
||||||
|
|
||||||
build_logs.delete_log_entries(to_archive.uuid)
|
build_logs.expire_log_entries(to_archive.uuid)
|
||||||
|
|
||||||
except RepositoryBuild.DoesNotExist:
|
except RepositoryBuild.DoesNotExist:
|
||||||
logger.debug('No more builds to archive')
|
logger.debug('No more builds to archive')
|
||||||
|
|
Reference in a new issue