File tree Expand file tree Collapse file tree 4 files changed +35
-8
lines changed
Expand file tree Collapse file tree 4 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 3232from agentkit .toolkit .models import BuildResult , ImageInfo
3333from agentkit .toolkit .reporter import Reporter
3434from agentkit .toolkit .errors import ErrorCode
35- from agentkit .utils .misc import generate_random_id , calculate_nonlinear_progress
35+ from agentkit .utils .misc import (
36+ generate_random_id ,
37+ calculate_nonlinear_progress ,
38+ retry ,
39+ )
3640from agentkit .toolkit .volcengine .services import CRServiceConfig
3741from .base import Builder
3842
@@ -1303,11 +1307,12 @@ def download_and_show_logs(run_id: str):
13031307
13041308 while True :
13051309 try :
1306- # Get pipeline run status
1307- status = cp_client .get_pipeline_run_status (
1308- workspace_id = workspace_id ,
1309- pipeline_id = pipeline_id ,
1310- run_id = run_id ,
1310+ status = retry (
1311+ lambda : cp_client .get_pipeline_run_status (
1312+ workspace_id = workspace_id ,
1313+ pipeline_id = pipeline_id ,
1314+ run_id = run_id ,
1315+ )
13111316 )
13121317
13131318 # Update progress description
Original file line number Diff line number Diff line change 3939 generate_apikey_name ,
4040 generate_client_token ,
4141 calculate_nonlinear_progress ,
42+ retry ,
4243)
4344from agentkit .sdk .runtime .client import AgentkitRuntimeClient
4445from agentkit .toolkit .volcengine .iam import VeIAM
@@ -834,8 +835,10 @@ def _wait_for_runtime_status_multiple(
834835 # Use reporter.long_task() for progress tracking
835836 with self .reporter .long_task (task_description , total = total_time ) as task :
836837 while True :
837- runtime = self .agentkit_runtime_client .get_runtime (
838- runtime_types .GetRuntimeRequest (runtime_id = runtime_id )
838+ runtime = retry (
839+ lambda : self .agentkit_runtime_client .get_runtime (
840+ runtime_types .GetRuntimeRequest (runtime_id = runtime_id )
841+ )
839842 )
840843
841844 # Check if target status reached
Original file line number Diff line number Diff line change 1616
1717from .agent_parser import AgentParser
1818
19+
1920__all__ = ["AgentParser" ]
Original file line number Diff line number Diff line change 1515import math
1616import string
1717import random
18+ import time
19+ from typing import Callable , TypeVar
20+
21+ T = TypeVar ("T" )
1822
1923
2024def generate_random_id (length = 8 ):
@@ -102,3 +106,17 @@ def calculate_nonlinear_progress(
102106 """
103107 progress = max_time * (1 - math .exp (- elapsed / expected_time ))
104108 return min (progress , max_time * max_ratio )
109+
110+
111+ def retry (
112+ func : Callable [[], T ],
113+ retries : int = 3 ,
114+ delay : float = 1.0 ,
115+ ) -> T :
116+ for attempt in range (retries ):
117+ try :
118+ return func ()
119+ except Exception : # noqa: BLE001
120+ if attempt == retries - 1 :
121+ raise
122+ time .sleep (delay )
You can’t perform that action at this time.
0 commit comments