def _copy_attachment_into_cache(attachment_id, attachment, cache_key, cache_timeout): fp = attachment.file.getfile() chunk = None chunk_index = 0 size = 0 while True: chunk = fp.read(settings.SENTRY_REPROCESSING_ATTACHMENT_CHUNK_SIZE) if not chunk: break size += len(chunk) attachment_cache.set_chunk( key=cache_key, id=attachment_id, chunk_index=chunk_index, chunk_data=chunk, timeout=cache_timeout, ) chunk_index += 1 assert size == attachment.file.size return CachedAttachment( key=cache_key, id=attachment_id, name=attachment.name, # XXX: Not part of eventattachment model, but not strictly # necessary for processing content_type=None, type=attachment.file.type, chunks=chunk_index, size=size, )
def process_attachment_chunk(message, projects): payload = message["payload"] event_id = message["event_id"] project_id = message["project_id"] id = message["id"] chunk_index = message["chunk_index"] cache_key = cache_key_for_event({"event_id": event_id, "project": project_id}) attachment_cache.set_chunk( key=cache_key, id=id, chunk_index=chunk_index, chunk_data=payload, timeout=CACHE_TIMEOUT )