Skip to content

Commit b3b4afd

Browse files
feat: feat: add option to wait for commit completion to push function
1 parent f71e29a commit b3b4afd

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

src/openlayer/lib/data/commit.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,28 @@ def push(
1818
project_id: str,
1919
message: str = "New commit",
2020
storage_type: Optional[StorageType] = None,
21-
) -> None:
21+
wait_for_completion: bool = False,
22+
verbose: bool = False,
23+
) -> Optional[CommitRetrieveResponse]:
2224
"""Push a new commit to the Openlayer platform.
2325
24-
This is equivalent to running `openlayer push` from the Openlayer CLI."""
26+
This is equivalent to running `openlayer push` from the Openlayer CLI.
27+
28+
If `wait_for_completion` is True, the function will wait for the commit to be
29+
completed and return the commit object.
30+
31+
Args:
32+
client: The Openlayer client.
33+
directory: The directory to push.
34+
project_id: The id of the project to push to.
35+
message: The commit message.
36+
storage_type: The storage type to use.
37+
wait_for_completion: Whether to wait for the commit to be completed.
38+
verbose: Whether to print verbose output.
39+
40+
Returns:
41+
The commit object if `wait_for_completion` is True, otherwise None.
42+
"""
2543
if not os.path.exists(directory):
2644
raise ValueError(f"Directory {directory} does not exist.")
2745

@@ -43,19 +61,36 @@ def push(
4361
)
4462

4563
# Create the project version (commit)
46-
client.projects.commits.create(
64+
commit = client.projects.commits.create(
4765
project_id=project_id,
4866
commit={"message": message, "source": "cli"},
4967
storage_uri=presigned_url_response.storage_uri,
5068
)
5169

70+
if wait_for_completion:
71+
return wait_for_commit_completion(
72+
client=client,
73+
project_version_id=commit.id,
74+
verbose=verbose,
75+
)
76+
77+
return None
78+
5279

5380
def wait_for_commit_completion(
5481
client: Openlayer, project_version_id: str, verbose: bool = True
5582
) -> CommitRetrieveResponse:
5683
"""Wait for a commit to be processed by the Openlayer platform.
5784
5885
Waits until the commit status is "completed" or "failed".
86+
87+
Args:
88+
client: The Openlayer client.
89+
project_version_id: The id of the project version (commit) to wait for.
90+
verbose: Whether to print verbose output.
91+
92+
Returns:
93+
The commit object.
5994
"""
6095
while True:
6196
commit = client.commits.retrieve(project_version_id=project_version_id)

0 commit comments

Comments
 (0)