Allow most builds to be archived without writing a file to the disk.

This commit is contained in:
Jake Moshenko 2014-09-16 00:03:04 -04:00
parent ab35c864f8
commit 15a2f0d56f

View file

@ -12,6 +12,7 @@ from app import build_logs, log_archive
from util.streamingjsonencoder import StreamingJSONEncoder
POLL_PERIOD_SECONDS = 30
MEMORY_TEMPFILE_SIZE = 64 * 1024 # Large enough to handle approximately 99% of builds in memory
logger = logging.getLogger(__name__)
sched = BlockingScheduler()
@ -32,7 +33,7 @@ def archive_redis_buildlogs():
'logs': entries,
}
with SpooledTemporaryFile() as tempfile:
with SpooledTemporaryFile(MEMORY_TEMPFILE_SIZE) as tempfile:
with GzipFile('testarchive', fileobj=tempfile) as zipstream:
for chunk in StreamingJSONEncoder().iterencode(to_encode):
zipstream.write(chunk)