diff --git a/app/adapters.py b/app/adapters.py index e4856fc..2bd2f7d 100644 --- a/app/adapters.py +++ b/app/adapters.py @@ -246,6 +246,12 @@ class LocalS3Storage: connect_timeout=3, read_timeout=10, retries={'max_attempts': 2}) self.client = boto3.client('s3', endpoint_url=os.environ['S3_ENDPOINT'], config=config) self.public = boto3.client('s3', endpoint_url=os.environ['S3_PUBLIC_ENDPOINT'], config=config) + # The worker's own reads and writes wait out a short storage outage + # (an R2 503, Sentry DTF-API-A): up to 10 tries with growing backoff, + # about two minutes. Requests a person waits on keep the 2 tries. + patient = Config(signature_version='s3v4', s3={'addressing_style': 'path'}, + connect_timeout=3, read_timeout=30, retries={'max_attempts': 10, 'mode': 'standard'}) + self.patient = boto3.client('s3', endpoint_url=os.environ['S3_ENDPOINT'], config=patient) self.bucket = os.environ['S3_BUCKET'] def initialize(self): @@ -287,11 +293,11 @@ class LocalS3Storage: def fetch(self, key, path): """Copy a stored object to a local file (the worker's scratch space).""" - self.client.download_file(self.bucket, key, path) + self.patient.download_file(self.bucket, key, path) def store(self, key, path, content_type): """Upload a file the service generated itself, such as a print file.""" - self.client.upload_file(path, self.bucket, key, ExtraArgs={'ContentType': content_type}) + self.patient.upload_file(path, self.bucket, key, ExtraArgs={'ContentType': content_type}) def download(self, key, name): from urllib.parse import quote diff --git a/app/printjobs.py b/app/printjobs.py index 9ab2c55..2d1d9c6 100644 --- a/app/printjobs.py +++ b/app/printjobs.py @@ -255,9 +255,17 @@ def render_one(storage): stored.append((uid, name, os.path.getsize(path), key)) store_tiles(storage, os.path.join(scratch, 'tiles', name), uid) except Exception as exc: - # Storage failing is an attempt like any other, not a claim held for an hour. - logging.exception('Storing the print file failed') - finish(job, 'failed' if job['attempts'] + 1 >= MAX_ATTEMPTS else 'pending', {'error': type(exc).__name__}) + # Storage failing is an attempt like any other, not a claim held for an + # hour. The storage client already waited out a short outage; Sentry + # hears of one that outlasts every attempt, once, not of each retry + # (Sentry DTF-API-A). + final = job['attempts'] + 1 >= MAX_ATTEMPTS + if final: + logging.exception('Storing the print file failed: order #%s item %s', job['number'], job['item_index'] + 1) + else: + logging.warning('Storing the print file failed, retrying: order #%s item %s: %s', + job['number'], job['item_index'] + 1, exc) + finish(job, 'failed' if final else 'pending', {'error': type(exc).__name__}) return True finally: shutil.rmtree(scratch, ignore_errors=True)