t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/AWS/Lambda/fixtures/durable-handler.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

49 lines
1.9 KiB
TypeScript

import * as Lambda from "@/AWS/Lambda";
import * as Duration from "effect/Duration";
import * as Effect from "effect/Effect";
import path from "pathe";
const main = path.resolve(import.meta.dirname, "durable-handler.ts");
/**
* A three-operation durable orchestration: two checkpointed steps around a
* durable sleep. The sleep suspends the execution (the invocation returns
* PENDING) and Lambda re-invokes the function to resume, so a SUCCEEDED
* result proves the full checkpoint/replay round-trip:
* invoke #1 — step "reserve" checkpoints, wait checkpoints, suspend
* invoke #2 — replay memoizes "reserve", runs "price", completes
*
* A DurableFunction IS the Lambda function (wrapper of AWS.Lambda.Function):
* the wrapper sets `DurableConfig` at create time, disables the Function URL,
* self-binds the checkpoint-protocol IAM, and vendors
* `@aws/durable-execution-sdk-js` into the artifact automatically.
*/
export class DurableFlow extends Lambda.DurableFunction<DurableFlow>()(
"DurableFlow",
) {}
export default DurableFlow.make(
{
main,
executionTimeout: Duration.hours(1),
retentionPeriod: "1 day",
// Per-invocation budget (each resume is its own invocation).
timeout: Duration.seconds(60),
},
Effect.gen(function* () {
return Effect.fn(function* (input: { orderId: string }) {
const reserved = yield* Lambda.Durable.step(
"reserve",
Effect.succeed({ orderId: input.orderId, reserved: true }),
);
yield* Lambda.Durable.sleep("cooldown", "5 seconds");
const total = yield* Lambda.Durable.step(
"price",
// Non-deterministic work belongs inside a step: the checkpointed
// result replays identically on the resume invocation.
Effect.sync(() => 40 + 2),
);
return { orderId: reserved.orderId, reserved: reserved.reserved, total };
});
}),
);