You've already forked FrameTour-RenderWorker
音轨叠加
This commit is contained in:
41
util/oss.py
41
util/oss.py
@ -22,8 +22,9 @@ def upload_to_oss(url, file_path):
|
||||
max_retries = 5
|
||||
retries = 0
|
||||
while retries < max_retries:
|
||||
try:
|
||||
with tracer.start_as_current_span("upload_to_oss.request") as req_span:
|
||||
with tracer.start_as_current_span("upload_to_oss.request") as req_span:
|
||||
req_span.set_attribute("http.retry_count", retries)
|
||||
try:
|
||||
req_span.set_attribute("http.method", "PUT")
|
||||
req_span.set_attribute("http.url", url)
|
||||
with open(file_path, 'rb') as f:
|
||||
@ -31,13 +32,14 @@ def upload_to_oss(url, file_path):
|
||||
req_span.set_attribute("http.status_code", response.status_code)
|
||||
if response.status_code == 200:
|
||||
return True
|
||||
except requests.exceptions.Timeout:
|
||||
retries += 1
|
||||
logger.warning(f"Upload timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
retries += 1
|
||||
span.set_attribute("oss.error", str(e))
|
||||
logger.warning(f"Upload failed. Retrying {retries}/{max_retries}...")
|
||||
except requests.exceptions.Timeout:
|
||||
req_span.set_attribute("http.error", "Timeout")
|
||||
retries += 1
|
||||
logger.warning(f"Upload timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
req_span.set_attribute("http.error", str(e))
|
||||
retries += 1
|
||||
logger.warning(f"Upload failed. Retrying {retries}/{max_retries}...")
|
||||
return False
|
||||
|
||||
|
||||
@ -60,20 +62,23 @@ def download_from_oss(url, file_path):
|
||||
max_retries = 5
|
||||
retries = 0
|
||||
while retries < max_retries:
|
||||
try:
|
||||
with tracer.start_as_current_span("download_from_oss.request") as req_span:
|
||||
with tracer.start_as_current_span("download_from_oss.request") as req_span:
|
||||
req_span.set_attribute("http.retry_count", retries)
|
||||
try:
|
||||
req_span.set_attribute("http.method", "GET")
|
||||
req_span.set_attribute("http.url", url)
|
||||
response = requests.get(url, timeout=15) # 设置超时时间
|
||||
req_span.set_attribute("http.status_code", response.status_code)
|
||||
with open(file_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
span.set_attribute("file.size", os.path.getsize(file_path))
|
||||
return True
|
||||
except requests.exceptions.Timeout:
|
||||
retries += 1
|
||||
logger.warning(f"Download timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
retries += 1
|
||||
span.set_attribute("oss.error", str(e))
|
||||
logger.warning(f"Download failed. Retrying {retries}/{max_retries}...")
|
||||
except requests.exceptions.Timeout:
|
||||
span.set_attribute("http.error", "Timeout")
|
||||
retries += 1
|
||||
logger.warning(f"Download timed out. Retrying {retries}/{max_retries}...")
|
||||
except Exception as e:
|
||||
span.set_attribute("http.error", str(e))
|
||||
retries += 1
|
||||
logger.warning(f"Download failed. Retrying {retries}/{max_retries}...")
|
||||
return False
|
||||
|
Reference in New Issue
Block a user