Finish the build logs archiver, add handlers for cloud and local that handle gzip encoded archived content.
This commit is contained in:
parent
2455c17f96
commit
8b3a3178b0
10 changed files with 82 additions and 18 deletions
|
@ -1,5 +1,30 @@
|
|||
import logging
|
||||
|
||||
from gzip import GzipFile
|
||||
from flask import send_file, abort
|
||||
from cStringIO import StringIO
|
||||
|
||||
from data.userfiles import DelegateUserfiles, UserfilesHandlers
|
||||
|
||||
|
||||
JSON_MIMETYPE = 'application/json'
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LogArchiveHandlers(UserfilesHandlers):
|
||||
def get(self, file_id):
|
||||
path = self._files.get_file_id_path(file_id)
|
||||
try:
|
||||
with self._storage.stream_read_file(self._locations, path) as gzip_stream:
|
||||
with GzipFile(fileobj=gzip_stream) as unzipped:
|
||||
unzipped_buffer = StringIO(unzipped.read())
|
||||
return send_file(unzipped_buffer, mimetype=JSON_MIMETYPE)
|
||||
except IOError:
|
||||
abort(404)
|
||||
|
||||
|
||||
class LogArchive(object):
|
||||
def __init__(self, app=None, distributed_storage=None):
|
||||
self.app = app
|
||||
|
@ -17,10 +42,10 @@ class LogArchive(object):
|
|||
log_archive = DelegateUserfiles(app, distributed_storage, location, path, handler_name)
|
||||
|
||||
app.add_url_rule('/logarchive/<file_id>',
|
||||
view_func=UserfilesHandlers.as_view(handler_name,
|
||||
distributed_storage=distributed_storage,
|
||||
location=location,
|
||||
files=log_archive))
|
||||
view_func=LogArchiveHandlers.as_view(handler_name,
|
||||
distributed_storage=distributed_storage,
|
||||
location=location,
|
||||
files=log_archive))
|
||||
|
||||
# register extension with app
|
||||
app.extensions = getattr(app, 'extensions', {})
|
||||
|
|
|
@ -51,6 +51,13 @@ class RedisBuildLogs(object):
|
|||
except redis.ConnectionError:
|
||||
raise BuildStatusRetrievalError('Cannot retrieve build logs')
|
||||
|
||||
def delete_log_entries(self, build_id):
|
||||
"""
|
||||
Deletes the logs and status keys completely.
|
||||
"""
|
||||
self._redis.delete(self._logs_key(build_id))
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _status_key(build_id):
|
||||
return 'builds/%s/status' % build_id
|
||||
|
|
|
@ -81,12 +81,13 @@ class DelegateUserfiles(object):
|
|||
|
||||
return (url, file_id)
|
||||
|
||||
def store_file(self, file_like_obj, content_type, file_id=None):
|
||||
def store_file(self, file_like_obj, content_type, content_encoding=None, file_id=None):
|
||||
if file_id is None:
|
||||
file_id = str(uuid4())
|
||||
|
||||
path = self.get_file_id_path(file_id)
|
||||
self._storage.stream_write(self._locations, path, file_like_obj, content_type)
|
||||
self._storage.stream_write(self._locations, path, file_like_obj, content_type,
|
||||
content_encoding)
|
||||
return file_id
|
||||
|
||||
def get_file_url(self, file_id, expires_in=300, requires_cors=False):
|
||||
|
|
Reference in a new issue