chore: test deploy snapshot
This commit is contained in:
@@ -193,7 +193,8 @@ function normalizeTestServerDeploymentSnapshot(value: unknown): TestServerDeploy
|
||||
export async function readTestServerDeploymentState(): Promise<TestServerDeploymentSnapshot | null> {
|
||||
try {
|
||||
const raw = await readFile(getTestServerDeploymentStatePath(), 'utf8');
|
||||
return normalizeTestServerDeploymentSnapshot(JSON.parse(raw));
|
||||
const snapshot = normalizeTestServerDeploymentSnapshot(JSON.parse(raw));
|
||||
return await resolveStaleRunningTestDeployment(snapshot);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
@@ -209,6 +210,62 @@ async function clearTestServerDeploymentState() {
|
||||
await rm(getTestServerDeploymentStatePath(), { force: true }).catch(() => undefined);
|
||||
}
|
||||
|
||||
function buildStaleTestServerDeploymentFailure(snapshot: TestServerDeploymentSnapshot) {
|
||||
const stalledAt = snapshot.updatedAt ?? snapshot.startedAt;
|
||||
const stalledLabel = stalledAt ? `마지막 상태 갱신 ${stalledAt}` : '상태 갱신 시각 확인 불가';
|
||||
return trimPreview(`TEST 배포 상태가 오래 갱신되지 않았고 잠금 파일도 없어 중단된 배포로 처리했습니다. ${stalledLabel}`, 500)
|
||||
?? 'TEST 배포 상태가 오래 갱신되지 않아 중단된 배포로 처리했습니다.';
|
||||
}
|
||||
|
||||
async function finalizeStaleRunningTestDeployment(snapshot: TestServerDeploymentSnapshot) {
|
||||
const failureMessage = buildStaleTestServerDeploymentFailure(snapshot);
|
||||
const now = new Date().toISOString();
|
||||
const activeStep = snapshot.steps.find((step) => step.status === 'running')?.key;
|
||||
|
||||
snapshot.status = 'failed';
|
||||
snapshot.phase = 'failed';
|
||||
snapshot.summary = buildTestServerDeploymentSummary('failed');
|
||||
snapshot.completedAt = now;
|
||||
snapshot.updatedAt = now;
|
||||
snapshot.lastError = failureMessage;
|
||||
|
||||
if (activeStep) {
|
||||
updateTestServerDeploymentStep(snapshot, activeStep, 'failed', failureMessage);
|
||||
}
|
||||
|
||||
await writeTestServerDeploymentState(snapshot);
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
async function resolveStaleRunningTestDeployment(snapshot: TestServerDeploymentSnapshot) {
|
||||
if (snapshot.status !== 'running') {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
const freshnessSource = snapshot.updatedAt ?? snapshot.startedAt;
|
||||
if (!freshnessSource) {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
const staleForMs = Date.now() - Date.parse(freshnessSource);
|
||||
if (!Number.isFinite(staleForMs) || staleForMs < TEST_SERVER_DEPLOYMENT_LOCK_STALE_MS) {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
const lockPath = getTestServerDeploymentLockPath();
|
||||
const lockStat = await stat(lockPath).catch(() => null);
|
||||
|
||||
if (lockStat?.isFile()) {
|
||||
const lockFreshnessSource = normalizeDateTimeValue(lockStat.mtime.toISOString() ?? null);
|
||||
if (lockFreshnessSource && Date.now() - Date.parse(lockFreshnessSource) < TEST_SERVER_DEPLOYMENT_LOCK_STALE_MS) {
|
||||
return snapshot;
|
||||
}
|
||||
}
|
||||
|
||||
await rm(lockPath, { force: true }).catch(() => undefined);
|
||||
return finalizeStaleRunningTestDeployment(snapshot);
|
||||
}
|
||||
|
||||
async function acquireTestServerDeploymentLock() {
|
||||
const lockPath = getTestServerDeploymentLockPath();
|
||||
await mkdir(path.dirname(lockPath), { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user