Merged
Show file tree
Hide file tree
Changes from 1 commit
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Failed to load files.
Next Next commit
feat: add cancel method to pipeline client
  • Loading branch information
@ji-yaqi
ji-yaqi committedJun 18, 2021
commit 11de187bdd43caf6940b4424d40c4256d2bd80f8
Original file line numberDiff line numberDiff line change
Expand Up@@ -264,7 +264,7 @@ def state(self) -> Optional[gca_pipeline_state_v1beta1.PipelineState]:
@property
def _has_run(self) -> bool:
"""Helper property to check if this pipeline job has been run."""
return bool(self._gca_resource.name)
return bool(self._gca_resource.create_time)

@property
def has_failed(self) -> bool:
Expand DownExpand Up@@ -310,3 +310,19 @@ def _block_until_complete(self):
log_wait = min(log_wait * multiplier, max_wait)
previous_time = current_time
time.sleep(wait)

def cancel(self) -> None:
"""Starts asynchronous cancellation on the PipelineJob. The server
makes a best effort to cancel the job, but success is not guaranteed.
On successful cancellation, the PipelineJob is not deleted; instead it
becomes a job with state set to `CANCELLED`.

Raises:
RuntimeError: If this PipelineJob has not started running.
"""
if not self._has_run:
raise RuntimeError(
"This PipelineJob has not been launched, use the `run()` method "
"to start. `cancel()` can only be called on a job that is running."
)
self.api_client.cancel_pipeline_job(name=self.resource_name)