fix(ci): retry workflow cancellation on 409 conflicts (#29584)
This commit is contained in:
@@ -72,11 +72,26 @@ jobs:
|
|||||||
if (latestRun.status === 'in_progress' || latestRun.status === 'queued') {
|
if (latestRun.status === 'in_progress' || latestRun.status === 'queued') {
|
||||||
console.log(`Workflow is running (status: ${latestRun.status}). Cancelling it first...`);
|
console.log(`Workflow is running (status: ${latestRun.status}). Cancelling it first...`);
|
||||||
|
|
||||||
await github.rest.actions.cancelWorkflowRun({
|
const cancelMaxRetries = 10;
|
||||||
owner: context.repo.owner,
|
const cancelRetryDelay = 3000;
|
||||||
repo: context.repo.repo,
|
for (let attempt = 1; attempt <= cancelMaxRetries; attempt++) {
|
||||||
run_id: latestRun.id,
|
try {
|
||||||
});
|
await github.rest.actions.cancelWorkflowRun({
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
run_id: latestRun.id,
|
||||||
|
});
|
||||||
|
console.log(`Cancel request accepted on attempt ${attempt}`);
|
||||||
|
break;
|
||||||
|
} catch (err) {
|
||||||
|
if (err.status === 409 && attempt < cancelMaxRetries) {
|
||||||
|
console.log(`Cancel attempt ${attempt} got 409 (not yet cancellable), retrying in ${cancelRetryDelay / 1000}s...`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, cancelRetryDelay));
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for the workflow to be cancelled (poll with timeout)
|
// Wait for the workflow to be cancelled (poll with timeout)
|
||||||
const maxWaitTime = 60000; // 60 seconds
|
const maxWaitTime = 60000; // 60 seconds
|
||||||
|
|||||||
Reference in New Issue
Block a user