t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Lambda/shutdown-probe.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

39 lines
1.3 KiB
TypeScript

import * as AWS from "@/AWS/index.ts";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
/**
* Probe for Lambda's Shutdown phase.
*
* The init closure registers an instance-scope finalizer that writes a
* marker to stdout (→ CloudWatch): the generated entry registers an
* internal extension, so Lambda grants the runtime a 500 ms SIGTERM window
* at sandbox spin-down in which the entry closes the instance scope — the
* marker appears exactly once per sandbox, never per invocation.
*
* The fetch handler registers a request-scope finalizer whose marker must
* appear once per invocation (the dispatch settles the request scope
* inline before returning).
*/
export default class ShutdownProbe extends AWS.Lambda.Function<ShutdownProbe>()(
"ShutdownProbe",
{
main: import.meta.url,
functionUrl: true,
timeout: Duration.seconds(10),
},
Effect.gen(function* () {
yield* Effect.addFinalizer(() =>
Effect.sync(() => console.log("ALCHEMY_INSTANCE_FINALIZED")),
);
return {
fetch: Effect.gen(function* () {
yield* Effect.addFinalizer(() =>
Effect.sync(() => console.log("ALCHEMY_REQUEST_FINALIZED")),
);
return HttpServerResponse.text("ok");
}),
};
}),
) {}