Compare commits

...

3 Commits

Author SHA1 Message Date
Robert b37e12b418 Use isInTestMode() instead of NODE_ENV 2026-06-02 10:01:35 +01:00
Robert d40e417f3c Only do initial wait when not running tests 2026-06-01 16:43:42 +01:00
Robert dfc14113e3 Change waitForProcessing to use exponential backoff 2026-05-28 11:15:07 +01:00
2 changed files with 45 additions and 32 deletions
+16 -12
View File
@@ -157473,22 +157473,20 @@ function dumpSarifFile(sarifPayload, outputDir, logger, uploadTarget) {
logger.info(`Writing processed SARIF file to ${outputFile}`); logger.info(`Writing processed SARIF file to ${outputFile}`);
fs21.writeFileSync(outputFile, sarifPayload); fs21.writeFileSync(outputFile, sarifPayload);
} }
var STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1e3; var STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS = 5 * 1e3;
var STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1e3; var STATUS_CHECK_BACKOFF_MULTIPLIER = 2;
var STATUS_CHECK_MAX_TRIES = 5;
async function waitForProcessing(repositoryNwo, sarifID, logger, options = { async function waitForProcessing(repositoryNwo, sarifID, logger, options = {
isUnsuccessfulExecution: false isUnsuccessfulExecution: false
}) { }) {
logger.startGroup("Waiting for processing to finish"); logger.startGroup("Waiting for processing to finish");
try { try {
const client = getApiClient(); const client = getApiClient();
const statusCheckingStarted = Date.now(); let statusCheckBackoff = STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS;
while (true) { if (!isInTestMode()) {
if (Date.now() > statusCheckingStarted + STATUS_CHECK_TIMEOUT_MILLISECONDS) { await delay(statusCheckBackoff, { allowProcessExit: false });
logger.warning(
"Timed out waiting for analysis to finish processing. Continuing."
);
break;
} }
for (let statusCheckCount = 1; statusCheckCount <= STATUS_CHECK_MAX_TRIES; statusCheckCount++) {
let response = void 0; let response = void 0;
try { try {
response = await client.request( response = await client.request(
@@ -157526,9 +157524,15 @@ ${response.data.errors}`;
} else { } else {
assertNever(status); assertNever(status);
} }
await delay(STATUS_CHECK_FREQUENCY_MILLISECONDS, { if (statusCheckCount === STATUS_CHECK_MAX_TRIES) {
allowProcessExit: false logger.warning(
}); "Timed out waiting for analysis to finish processing. Continuing."
);
break;
} else {
statusCheckBackoff *= STATUS_CHECK_BACKOFF_MULTIPLIER;
await delay(statusCheckBackoff, { allowProcessExit: false });
}
} }
} finally { } finally {
logger.endGroup(); logger.endGroup();
+27 -18
View File
@@ -36,6 +36,7 @@ import {
getRequiredEnvParam, getRequiredEnvParam,
GitHubVariant, GitHubVariant,
GitHubVersion, GitHubVersion,
isInTestMode,
satisfiesGHESVersion, satisfiesGHESVersion,
} from "./util"; } from "./util";
@@ -829,8 +830,10 @@ function dumpSarifFile(
fs.writeFileSync(outputFile, sarifPayload); fs.writeFileSync(outputFile, sarifPayload);
} }
const STATUS_CHECK_FREQUENCY_MILLISECONDS = 5 * 1000; // Should lead to status checks after 5s, 15s, 35s, 75s, and 155s.
const STATUS_CHECK_TIMEOUT_MILLISECONDS = 2 * 60 * 1000; const STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS = 5 * 1000;
const STATUS_CHECK_BACKOFF_MULTIPLIER = 2;
const STATUS_CHECK_MAX_TRIES = 5;
type ProcessingStatus = "pending" | "complete" | "failed"; type ProcessingStatus = "pending" | "complete" | "failed";
@@ -854,20 +857,17 @@ export async function waitForProcessing(
try { try {
const client = api.getApiClient(); const client = api.getApiClient();
const statusCheckingStarted = Date.now(); // Do an initial wait because processing will always take a minimum of 2-3 seconds
while (true) { let statusCheckBackoff = STATUS_CHECK_INITIAL_BACKOFF_MILLISECONDS;
if ( if (!isInTestMode()) {
Date.now() > await util.delay(statusCheckBackoff, { allowProcessExit: false });
statusCheckingStarted + STATUS_CHECK_TIMEOUT_MILLISECONDS
) {
// If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
// It's possible the analysis will eventually finish processing, but it's not worth spending more
// Actions time waiting.
logger.warning(
"Timed out waiting for analysis to finish processing. Continuing.",
);
break;
} }
for (
let statusCheckCount = 1;
statusCheckCount <= STATUS_CHECK_MAX_TRIES;
statusCheckCount++
) {
let response: OctokitResponse<any> | undefined = undefined; let response: OctokitResponse<any> | undefined = undefined;
try { try {
response = await client.request( response = await client.request(
@@ -912,9 +912,18 @@ export async function waitForProcessing(
util.assertNever(status); util.assertNever(status);
} }
await util.delay(STATUS_CHECK_FREQUENCY_MILLISECONDS, { if (statusCheckCount === STATUS_CHECK_MAX_TRIES) {
allowProcessExit: false, // If the analysis hasn't finished processing in the allotted time, we continue anyway rather than failing.
}); // It's possible the analysis will eventually finish processing, but it's not worth spending more
// Actions time waiting.
logger.warning(
"Timed out waiting for analysis to finish processing. Continuing.",
);
break;
} else {
statusCheckBackoff *= STATUS_CHECK_BACKOFF_MULTIPLIER;
await util.delay(statusCheckBackoff, { allowProcessExit: false });
}
} }
} finally { } finally {
logger.endGroup(); logger.endGroup();