@@ -120,9 +120,9 @@ jobs:
120120 print("No GitHub token available to cancel other workers")
121121 return
122122
123- # Get current run ID and job ID
123+ # Get current run ID and worker ID
124124 run_id = os.environ.get('GITHUB_RUN_ID')
125- current_job_id = os.environ['JOB_ID']
125+ current_worker = os.environ.get('WORKER_ID')
126126
127127 headers = {
128128 'Authorization': f'token {token}',
@@ -134,10 +134,25 @@ jobs:
134134 response = requests.get(url, headers=headers)
135135 if response.status_code == 200:
136136 jobs = response.json()['jobs']
137+ current_job = None
138+
139+ # Find current job by matrix variables
140+ for job in jobs:
141+ if (job['name'].startswith('read-events') and
142+ 'matrix' in job and
143+ 'worker' in job['matrix'] and
144+ str(job['matrix']['worker']) == current_worker):
145+ current_job = job
146+ break
147+
148+ if not current_job:
149+ print(f"Could not find current job for worker {current_worker}")
150+ return
151+
152+ # Cancel other read-events jobs
137153 for job in jobs:
138- # Only cancel other read-events jobs that are in progress
139154 if (job['name'].startswith('read-events') and
140- job['id'] != int(current_job_id) and
155+ job['id'] != current_job['id'] and
141156 job['status'] in ['queued', 'in_progress']):
142157 cancel_url = f"{url}/{job['id']}/cancel"
143158 cancel_response = requests.post(cancel_url, headers=headers)
0 commit comments