Auto expire the build status and logs in redis
This commit is contained in:
parent
6dd7fe21f9
commit
3b994431eb
2 changed files with 11 additions and 2 deletions
|
@ -7,6 +7,7 @@ from datetime import timedelta
|
|||
|
||||
|
||||
ONE_DAY = timedelta(days=1)
|
||||
SEVEN_DAYS = timedelta(days=7)
|
||||
|
||||
|
||||
class BuildStatusRetrievalError(Exception):
|
||||
|
@ -33,6 +34,7 @@ class RedisBuildLogs(object):
|
|||
Appends the serialized form of log_obj to the end of the log entry list
|
||||
and returns the new length of the list.
|
||||
"""
|
||||
self._redis.expire(self._logs_key(build_id), SEVEN_DAYS)
|
||||
return self._redis.rpush(self._logs_key(build_id), json.dumps(log_obj))
|
||||
|
||||
def append_log_message(self, build_id, log_message, log_type=None, log_data=None):
|
||||
|
@ -50,7 +52,7 @@ class RedisBuildLogs(object):
|
|||
if log_data:
|
||||
log_obj['data'] = log_data
|
||||
|
||||
return self._redis.rpush(self._logs_key(build_id), json.dumps(log_obj)) - 1
|
||||
return self.append_log_entry(build_id, log_obj) - 1
|
||||
|
||||
def get_log_entries(self, build_id, start_index):
|
||||
"""
|
||||
|
@ -64,6 +66,12 @@ class RedisBuildLogs(object):
|
|||
except redis.RedisError as re:
|
||||
raise BuildStatusRetrievalError('Cannot retrieve build logs: %s' % re)
|
||||
|
||||
def expire_status(self, build_id):
|
||||
"""
|
||||
Sets the status entry to expire in 1 day.
|
||||
"""
|
||||
self._redis.expire(self._status_key(build_id), ONE_DAY)
|
||||
|
||||
def expire_log_entries(self, build_id):
|
||||
"""
|
||||
Sets the log entry to expire in 1 day.
|
||||
|
@ -79,7 +87,7 @@ class RedisBuildLogs(object):
|
|||
Sets the status key for this build to json serialized form of the supplied
|
||||
obj.
|
||||
"""
|
||||
self._redis.set(self._status_key(build_id), json.dumps(status_obj))
|
||||
self._redis.set(self._status_key(build_id), json.dumps(status_obj), ex=SEVEN_DAYS)
|
||||
|
||||
def get_status(self, build_id):
|
||||
"""
|
||||
|
|
|
@ -52,6 +52,7 @@ class ArchiveBuildLogsWorker(Worker):
|
|||
to_update.logs_archived = True
|
||||
to_update.save()
|
||||
|
||||
build_logs.expire_status(to_update.uuid)
|
||||
build_logs.expire_log_entries(to_update.uuid)
|
||||
|
||||
|
||||
|
|
Reference in a new issue