Skip to content

Commit ee5bb4b

Browse files
committed
test
Signed-off-by: Charlie Truong <[email protected]>
1 parent c4c9268 commit ee5bb4b

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

.github/workflows/azure-queue-events.yaml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,15 @@ jobs:
9797
- name: Install Azure Storage SDK
9898
run: |
9999
python -m pip install --upgrade pip
100-
pip install azure-storage-queue azure-identity
100+
pip install azure-storage-queue azure-identity requests
101101
102102
- name: Read Events
103103
run: |
104104
python - <<EOF
105105
import os
106106
import json
107107
import time
108+
import requests
108109
from azure.storage.queue import QueueServiceClient
109110
from azure.identity import DefaultAzureCredential
110111
@@ -115,32 +116,31 @@ jobs:
115116
print("No GitHub token available to cancel other workers")
116117
return
117118
118-
# Get current run ID and workflow ID
119+
# Get current run ID and job ID
119120
run_id = os.environ.get('GITHUB_RUN_ID')
120-
workflow_id = os.environ.get('GITHUB_WORKFLOW_ID')
121+
job_id = os.environ.get('GITHUB_JOB')
121122
122-
# Get all runs of this workflow
123123
headers = {
124124
'Authorization': f'token {token}',
125125
'Accept': 'application/vnd.github.v3+json'
126126
}
127127
128-
# Cancel all other runs of this workflow
129-
url = f"https://api.github.com/repos/{os.environ.get('GITHUB_REPOSITORY')}/actions/runs"
128+
# Get all jobs in the current workflow run
129+
url = f"https://api.github.com/repos/{os.environ.get('GITHUB_REPOSITORY')}/actions/runs/{run_id}/jobs"
130130
response = requests.get(url, headers=headers)
131131
if response.status_code == 200:
132-
runs = response.json()['workflow_runs']
133-
for run in runs:
134-
if (run['id'] != int(run_id) and
135-
run['workflow_id'] == int(workflow_id) and
136-
run['status'] in ['queued', 'in_progress'] and
137-
run['name'].startswith('read-events')):
138-
cancel_url = f"{url}/{run['id']}/cancel"
132+
jobs = response.json()['jobs']
133+
for job in jobs:
134+
# Only cancel other read-events jobs that are in progress
135+
if (job['name'].startswith('read-events') and
136+
job['id'] != int(job_id) and
137+
job['status'] in ['queued', 'in_progress']):
138+
cancel_url = f"{url}/{job['id']}/cancel"
139139
cancel_response = requests.post(cancel_url, headers=headers)
140140
if cancel_response.status_code == 202:
141-
print(f"Cancelled run {run['id']} ({run['name']})")
141+
print(f"Cancelled job {job['id']} ({job['name']})")
142142
else:
143-
print(f"Failed to cancel run {run['id']}: {cancel_response.text}")
143+
print(f"Failed to cancel job {job['id']}: {cancel_response.text}")
144144
145145
# Create queue service client using managed identity
146146
account_url = f"https://{os.environ.get('AZURE_QUEUE_STORAGE_ACCOUNT')}.queue.core.windows.net"
@@ -211,6 +211,7 @@ jobs:
211211

212212
cleanup-queue:
213213
needs: read-events
214+
if: always() # Run even if read-events was cancelled
214215
runs-on: ubuntu-latest
215216
environment: nemo-ci
216217
permissions:

0 commit comments

Comments
 (0)