Skip to content

Commit f71e29a

Browse files
feat: feat: add wait_for_commit_completion convenience method
1 parent 3eb89ff commit f71e29a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/openlayer/lib/data/commit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import os
44
import tarfile
55
import tempfile
6+
import time
67
from typing import Optional
78

89

910
from ... import Openlayer
1011
from . import StorageType, _upload
12+
from ...types.commit_retrieve_response import CommitRetrieveResponse
1113

1214

1315
def push(
@@ -46,3 +48,30 @@ def push(
4648
commit={"message": message, "source": "cli"},
4749
storage_uri=presigned_url_response.storage_uri,
4850
)
51+
52+
53+
def wait_for_commit_completion(
54+
client: Openlayer, project_version_id: str, verbose: bool = True
55+
) -> CommitRetrieveResponse:
56+
"""Wait for a commit to be processed by the Openlayer platform.
57+
58+
Waits until the commit status is "completed" or "failed".
59+
"""
60+
while True:
61+
commit = client.commits.retrieve(project_version_id=project_version_id)
62+
if commit.status == "completed":
63+
if verbose:
64+
print(f"Commit {project_version_id} completed successfully.")
65+
return commit
66+
elif commit.status == "failed":
67+
raise Exception(
68+
f"Commit {project_version_id} failed with status message:"
69+
f" {commit.status_message}"
70+
)
71+
else:
72+
if verbose:
73+
print(
74+
f"Commit {project_version_id} is still processing (status:"
75+
f" {commit.status})..."
76+
)
77+
time.sleep(1)

0 commit comments

Comments
 (0)