Files
sora_python/app/service/lookbooks/utils/openai_utils.py
2024-10-21 11:01:28 +08:00

32 lines
974 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import time
def wait_for_job_completion(client, batch_job_id, timeout=6000, interval=10):
"""
等待批处理作业完成。
参数:
- client: 批处理作业客户端对象
- batch_job_id: 批处理作业的ID
- timeout: 最大等待时间(秒)
- interval: 检查状态的间隔时间(秒)
返回:
- True 如果作业完成False 如果超时
"""
start_time = time.time()
while time.time() - start_time < timeout:
batch_job = client.batches.retrieve(batch_job_id)
if batch_job.status == 'completed':
print("Batch job completed successfully.")
return True
elif batch_job.status == 'failed':
print("Batch job failed.")
return False
else:
print(f"Current status: {batch_job.status}. Waiting for completion...")
time.sleep(interval)
print("Timeout reached, job did not complete in time.")
return False