def get_release_file_cache_key_meta(release_id, releasefile_ident): return "meta:%s" % get_release_file_cache_key(release_id, releasefile_ident) MAX_FETCH_ATTEMPTS = 3 def should_retry_fetch(attempt: int, e: Exception) -> bool: return not attempt > MAX_FETCH_ATTEMPTS and isinstance( e, OSError) and e.errno == errno.ESTALE fetch_retry_policy = ConditionalRetryPolicy(should_retry_fetch, exponential_delay(0.05)) def fetch_release_file(filename, release, dist=None): """ Attempt to retrieve a release artifact from the database. Caches the result of that attempt (whether successful or not). """ dist_name = dist and dist.name or None releasefile_ident = ReleaseFile.get_ident(filename, dist_name) cache_key = get_release_file_cache_key(release_id=release.id, releasefile_ident=releasefile_ident) # Cache key to store file metadata, currently only the size of the # compressed version of file. We cannot use the cache_key because large
def get_release_file_cache_key(release_id, releasefile_ident): return f"releasefile:v1:{release_id}:{releasefile_ident}" def get_release_file_cache_key_meta(release_id, releasefile_ident): return "meta:%s" % get_release_file_cache_key(release_id, releasefile_ident) MAX_FETCH_ATTEMPTS = 3 def should_retry_fetch(attempt: int, e: Exception) -> bool: return not attempt > MAX_FETCH_ATTEMPTS and isinstance(e, OSError) and e.errno == errno.ESTALE fetch_retry_policy = ConditionalRetryPolicy(should_retry_fetch, exponential_delay(0.05)) def fetch_release_file(filename, release, dist=None): """ Attempt to retrieve a release artifact from the database. Caches the result of that attempt (whether successful or not). """ dist_name = dist and dist.name or None releasefile_ident = ReleaseFile.get_ident(filename, dist_name) cache_key = get_release_file_cache_key( release_id=release.id, releasefile_ident=releasefile_ident ) # Cache key to store file metadata, currently only the size of the