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
|
||||
|
||||
from util.dynamic import import_class
|
||||
from datetime import timedelta
|
||||
|
||||
|
||||
ONE_DAY = timedelta(days=1)
|
||||
|
||||
|
||||
class BuildStatusRetrievalError(Exception):
|
||||
pass
|
||||
|
@ -54,11 +59,11 @@ class RedisBuildLogs(object):
|
|||
except redis.ConnectionError:
|
||||
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
|
||||
|
|
|
@ -199,10 +199,10 @@ class TestBuildLogs(RedisBuildLogs):
|
|||
else:
|
||||
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:
|
||||
return
|
||||
if not self.allow_delegate:
|
||||
return None
|
||||
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.save()
|
||||
|
||||
build_logs.delete_log_entries(to_archive.uuid)
|
||||
build_logs.expire_log_entries(to_archive.uuid)
|
||||
|
||||
except RepositoryBuild.DoesNotExist:
|
||||
logger.debug('No more builds to archive')
|
||||
|
|
Reference in a new issue