Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Cancel queued AzureML jobs when starting a PR build #640

Merged
merged 26 commits into from
Jan 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
diag
  • Loading branch information
ant0nsc committed Jan 24, 2022
commit 62602ccfc3ac376d13a32d6b9bfbf7ab615ec7ac
11 changes: 9 additions & 2 deletions azure-pipelines/cancel_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,33 @@

def cancel_running_and_queued_jobs() -> None:
environ = os.environ
print("Authenticating")
auth = ServicePrincipalAuthentication(
tenant_id='72f988bf-86f1-41af-91ab-2d7cd011db47',
service_principal_id=environ["APPLICATION_ID"],
service_principal_password=environ["APPLICATION_KEY"])
print("Getting AML workspace")
workspace = Workspace.get(
name="InnerEye-DeepLearning",
auth=auth,
subscription_id=environ["SUBSCRIPTION_ID"],
resource_group="InnerEye-DeepLearning")
branch = environ["BRANCH"]
print(f"Branch: {branch}")
if not branch.startswith("refs/pull/"):
print(f"This branch is not a PR branch, hence not cancelling anything: {branch}")
print(f"This branch is not a PR branch, hence not cancelling anything.")
exit(0)
experiment_name = branch.replace("/", "_")
print(f"Experiment: {experiment_name}")
experiment = Experiment(workspace, name=experiment_name)
print(f"Retrieved experiment {experiment.name}")
for run in experiment.get_runs(include_children=True, properties={}):
assert isinstance(run, Run)
if run.status in (RunStatus.QUEUED, RunStatus.RUNNING):
print(f"Cancelling run {run.id} ({run.display_name})")
# run.cancel()
run.cancel()
else:
print(f"Skipping run {run.id} ({run.display_name}) with status {run.status}")


if __name__ == "__main__":
Expand Down