35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const RECOVERABLE_KINDS = new Set(["CHUNK_LOAD_FAILURE", "DEPLOY_MISMATCH"]);
|
|
|
|
/**
|
|
* @param {{
|
|
* failureKind: string,
|
|
* manifestLoaded: boolean,
|
|
* currentBuildId: string,
|
|
* activeReleaseId: string,
|
|
* storage: import("../ports/storage-port.js").StoragePort
|
|
* }} input
|
|
*/
|
|
export function decideChunkRecovery(input) {
|
|
if (!RECOVERABLE_KINDS.has(input.failureKind)) {
|
|
return { action: "support", reason: "not-recoverable" };
|
|
}
|
|
if (!input.manifestLoaded) {
|
|
return { action: "support", reason: "manifest-unavailable" };
|
|
}
|
|
if (input.activeReleaseId === input.currentBuildId) {
|
|
return { action: "support", reason: "same-release" };
|
|
}
|
|
|
|
const releasePair = `${input.currentBuildId}->${input.activeReleaseId}`;
|
|
const guard = input.storage.read("CHUNK_RELOAD_GUARD");
|
|
if (!guard.ok || guard.value === releasePair) {
|
|
return { action: "support", reason: "reload-already-attempted" };
|
|
}
|
|
|
|
const recorded = input.storage.write("CHUNK_RELOAD_GUARD", releasePair);
|
|
if (!recorded.ok) {
|
|
return { action: "support", reason: "guard-write-failed" };
|
|
}
|
|
return { action: "reload-once", releasePair };
|
|
}
|