Skip to content

Commit ebf4a70

Browse files
committed
fix: add retry for get runtime and pipeline
(cherry picked from commit 7e63c9c2d85a7306a3faa577cf26a5d4e6cbfa45)
1 parent 8595216 commit ebf4a70

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

agentkit/toolkit/builders/ve_pipeline.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
from agentkit.toolkit.models import BuildResult, ImageInfo
3333
from agentkit.toolkit.reporter import Reporter
3434
from 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+
)
3640
from agentkit.toolkit.volcengine.services import CRServiceConfig
3741
from .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

agentkit/toolkit/runners/ve_agentkit.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
generate_apikey_name,
4040
generate_client_token,
4141
calculate_nonlinear_progress,
42+
retry,
4243
)
4344
from agentkit.sdk.runtime.client import AgentkitRuntimeClient
4445
from 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

agentkit/toolkit/utils/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616

1717
from .agent_parser import AgentParser
1818

19+
1920
__all__ = ["AgentParser"]

agentkit/utils/misc.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import math
1616
import string
1717
import random
18+
import time
19+
from typing import Callable, TypeVar
20+
21+
T = TypeVar("T")
1822

1923

2024
def 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)

0 commit comments

Comments
 (0)