t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/ECS/reclaimTaskDefinitionFamily.ts
Julius Marminge 108e01746c
Upgrade Effect and Alchemy betas (#4643)
Prepare Relay production infrastructure for the PlanetScale PS_20 HA topology, upgrade Effect and Alchemy to compatible betas, reconcile migration state, and preserve patched MCP session termination behavior.\n\nCo-authored-by: codex <codex@users.noreply.github.com>
2026-07-27 16:21:02 +02:00

46 lines
1.8 KiB
TypeScript

import * as ecs from "@distilled.cloud/aws/ecs";
import * as Effect from "effect/Effect";
/**
* Fully reclaim every revision of an out-of-band task definition family:
* deregister any ACTIVE revisions, then hard-delete the INACTIVE revisions
* via `deleteTaskDefinitions` (deregistering alone leaves them INACTIVE,
* which still shows up in a live `listTaskDefinitions --status INACTIVE`
* sweep).
*
* Idempotent — run it BEFORE a test to recover leftovers from a previously
* killed run (the family names are deterministic, so a re-run reclaims a
* prior orphan instead of stacking new revisions forever), and as a
* finalizer AFTER the test so a passing test leaves zero task definitions
* behind.
*/
export const reclaimTaskDefinitionFamily = (family: string) =>
Effect.gen(function* () {
// `familyPrefix` is a prefix match — filter to the exact family so a
// family that happens to prefix another test's family is untouched.
const list = (status: "ACTIVE" | "INACTIVE") =>
ecs
.listTaskDefinitions({ familyPrefix: family, status })
.pipe(
Effect.map((r) =>
(r.taskDefinitionArns ?? []).filter((arn) =>
arn.includes(`/${family}:`),
),
),
);
const active = yield* list("ACTIVE");
yield* Effect.forEach(active, (arn) =>
ecs
.deregisterTaskDefinition({ taskDefinition: arn })
.pipe(Effect.catchTag("ClientException", () => Effect.void)),
);
const inactive = yield* list("INACTIVE");
// deleteTaskDefinitions accepts at most 10 ARNs per call.
for (let i = 0; i < inactive.length; i += 10) {
yield* ecs
.deleteTaskDefinitions({ taskDefinitions: inactive.slice(i, i + 10) })
.pipe(Effect.catchTag("ClientException", () => Effect.void));
}
});