t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/GCP/CloudScheduler/fixtures/schedule-service.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

49 lines
1.5 KiB
TypeScript

import * as GCP from "@/GCP";
import * as Effect from "effect/Effect";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
export const SCHEDULE_ID = "Heartbeat";
export const SCHEDULE_BODY = "hello-scheduler";
/** Marker object the consumer writes for one scheduled run. */
export const markerFor = (jobName: string) => `markers/${jobName}.json`;
/** Bucket the consumer records runs in. */
export const Markers = GCP.Storage.Bucket("ScheduleMarkers", {
location: "US-CENTRAL1",
forceDestroy: true,
});
/**
* Effect-native Cloud Run service that consumes a (yearly, so never
* naturally firing during a test) Cloud Scheduler job and records each run
* as a marker object. Deployed from {@link ../ScheduleEventSource.test.ts}.
*/
export default class ScheduleService extends GCP.Function<ScheduleService>()(
"ScheduleService",
{
main: import.meta.url,
location: "us-central1",
},
Effect.gen(function* () {
const bucket = yield* Markers;
const putObject = yield* GCP.Storage.PutObject(bucket);
yield* GCP.CloudScheduler.consumeSchedule(
SCHEDULE_ID,
{ schedule: "0 0 1 1 *", timeZone: "Etc/UTC", body: SCHEDULE_BODY },
(event) =>
putObject({
name: markerFor(event.jobName),
body: JSON.stringify(event),
}).pipe(Effect.asVoid, Effect.orDie),
);
return {
fetch: Effect.succeed(HttpServerResponse.text("ok")),
};
}).pipe(
Effect.provide(GCP.Run.ScheduleEventSource),
Effect.provide(GCP.Storage.PutObjectHttp),
),
) {}