fix: the worker waits out a short storage outage, and Sentry hears of one that outlasts the attempts once (DTF-API-A)
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 7m2s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m53s
All checks were successful
Build and deploy / Validate source (push) Successful in 6s
Build and deploy / Integration suite on a real stack (push) Successful in 7m2s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m53s
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user