fix: retry transient organization verification failures in CI
Deploy EG-BIM QA Gateway / deploy (push) Successful in 41s

This commit is contained in:
root committed 2026-10-29 15:09:39 +09:00
1 parent 03f2cd3b65
commit 250221aecf
5 files changed
+124 -17

No files matched your search

+33 -13
View File
@@ -1,19 +1,39 @@
import { getOrgDirectory } from '../src/org-context.js';
import { deploymentOrgSettings } from './org-context-settings.mjs';
import { setTimeout as wait } from 'node:timers/promises';
import { pathToFileURL } from 'node:url';
try {
const { vars, secrets } = deploymentOrgSettings(process.env);
export async function verifyOrganization(env = process.env, { fetchImpl = fetch, pause = wait, log = console.log } = {}) {
const { vars, secrets } = deploymentOrgSettings(env);
if (vars.ORG_CONTEXT_ENABLED !== 'true') {
console.log('Organization integration disabled; existing behavior retained.');
} else {
const directory = await getOrgDirectory({ ...vars, ...secrets });
console.log(JSON.stringify({
status: 'verified', rootCount: JSON.parse(vars.ORG_CONTEXT_TENANT_IDS).length,
tenantCount: directory.tenantCount, userCount: directory.byUser.size,
membershipCount: directory.membershipCount
}));
log('Organization integration disabled; existing behavior retained.');
return;
}
for (let attempt = 1; attempt <= 3; attempt++) {
try {
// CI can wait for a slow upstream without extending the page request timeout.
const directory = await getOrgDirectory({ ...vars, ...secrets }, { fetchImpl, timeoutMs: 15000 });
const summary = {
status: 'verified', rootCount: JSON.parse(vars.ORG_CONTEXT_TENANT_IDS).length,
tenantCount: directory.tenantCount, userCount: directory.byUser.size,
membershipCount: directory.membershipCount
};
log(JSON.stringify(summary));
return summary;
} catch (error) {
const retryable = /^org_context_(timeout|request_failed|http_(429|502|503|504))$/.test(error?.message || '');
if (!retryable || attempt === 3) throw error;
log(`Organization verification attempt ${attempt}/3 failed (${error.message}); retrying.`);
await pause(2000);
}
}
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
try {
await verifyOrganization();
} catch (error) {
console.error(/^org_context_[a-z0-9_]+$/.test(error?.message || '') ? error.message : 'Organization integration configuration or verification failed.');
process.exitCode = 1;
}
} catch (error) {
console.error(/^org_context_[a-z0-9_]+$/.test(error?.message || '') ? error.message : 'Organization integration configuration or verification failed.');
process.exitCode = 1;
}