From 177694edd3829ef42179eb34762051cd5bbf36cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 19 Nov 2026 09:52:25 -0300 Subject: [PATCH] fix: the worker waits out a short storage outage, and Sentry hears of one that outlasts the attempts once (DTF-API-A) R2 answered 503 while a print file tile of #53 was stored, and botocore's two tries ran out. The worker's own reads and writes (store, fetch) now use a client with up to 10 tries in standard mode, about two minutes of backoff; requests a person waits on keep two. A storage failure that still happens is a warning while the job has attempts left and an error on the last one. Co-Authored-By: Claude Opus 5.5 (1M context) --- app/adapters.py | 10 ++++++++-- app/printjobs.py | 14 +++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) 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)