| 1 | import type * as ECS from "@distilled.cloud/aws/ecs"; |
| 2 | import type * as Duration from "effect/Duration"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { Cluster } from "./Cluster.ts"; |
| 6 | |
| 7 | export interface UpdateTaskProtectionRequest extends Omit< |
| 8 | ECS.UpdateTaskProtectionRequest, |
| 9 | "cluster" | "expiresInMinutes" |
| 10 | > { |
| 11 | /** |
| 12 | * How long the protection should last, e.g. `"20 minutes"` or |
| 13 | * `Duration.hours(1)`. Rounded to whole minutes on the wire |
| 14 | * (1 minute – 48 hours). |
| 15 | * @default "2 hours" |
| 16 | */ |
| 17 | expiresIn?: Duration.Input; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Runtime binding for `ecs:UpdateTaskProtection`. |
| 22 | * |
| 23 | * Bind this operation to a `Cluster` inside a function runtime to get a |
| 24 | * callable that toggles scale-in protection on service-managed tasks in the |
| 25 | * bound cluster — the canonical pattern is a task protecting *itself* while |
| 26 | * it processes long-running work so deployments and scale-in don't terminate |
| 27 | * it. The cluster ARN is injected automatically and the host is granted |
| 28 | * `ecs:UpdateTaskProtection` on the cluster's tasks. |
| 29 | * ### Task Protection |
| 30 | * **Example:** Protect a Task While It Works |
| 31 | * ```typescript |
| 32 | * const updateTaskProtection = yield* AWS.ECS.UpdateTaskProtection(cluster); |
| 33 | * |
| 34 | * yield* updateTaskProtection({ |
| 35 | * tasks: [taskArn], |
| 36 | * protectionEnabled: true, |
| 37 | * expiresIn: "30 minutes", |
| 38 | * }); |
| 39 | * ``` |
| 40 | * |
| 41 | * @binding |
| 42 | */ |
| 43 | export interface UpdateTaskProtection extends Binding.Service< |
| 44 | UpdateTaskProtection, |
| 45 | "AWS.ECS.UpdateTaskProtection", |
| 46 | ( |
| 47 | cluster: Cluster, |
| 48 | ) => Effect.Effect< |
| 49 | ( |
| 50 | request: UpdateTaskProtectionRequest, |
| 51 | ) => Effect.Effect< |
| 52 | ECS.UpdateTaskProtectionResponse, |
| 53 | ECS.UpdateTaskProtectionError |
| 54 | > |
| 55 | > |
| 56 | > {} |
| 57 | export const UpdateTaskProtection = Binding.Service<UpdateTaskProtection>( |
| 58 | "AWS.ECS.UpdateTaskProtection", |
| 59 | ); |