diff --git a/data/buildlogs.py b/data/buildlogs.py index 027093f66..90a5fd2e7 100644 --- a/data/buildlogs.py +++ b/data/buildlogs.py @@ -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): """ diff --git a/workers/buildlogsarchiver.py b/workers/buildlogsarchiver.py index e29417c92..c2ca6b586 100644 --- a/workers/buildlogsarchiver.py +++ b/workers/buildlogsarchiver.py @@ -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)