DigitalOcean.App Platform reference
Source:
packages/digitalocean/src/App.ts
A DigitalOcean App Platform app running your program as an HTTPS service
with autoscaled instances behind App Platform’s load balancer and CDN.
Alchemy builds the program into an image, pushes it to the team’s
Container Registry, and deploys it; reconcile returns once the
deployment is live.
App: Effect App
Section titled “App: Effect App”export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url, region: "nyc" }, Effect.gen(function* () { return { fetch: Effect.gen(function* () { return yield* HttpServerResponse.json({ ok: true }); }), }; }),) {}App: Async App
Section titled “App: Async App”export const Ping = DigitalOcean.App("Ping", { main: "./src/ping.ts", env: { GREETING: "hello" },});export type PingEnv = DigitalOcean.InferEnv<typeof Ping>;import type { PingEnv } from "../alchemy.run.ts";
export default { async fetch(_request: Request, env: PingEnv) { return new Response(env.GREETING); },};App: Running an Image
Section titled “App: Running an Image”const web = yield* DigitalOcean.App("Web", { context: "./web", port: 3000, instanceSizeSlug: "apps-d-1vcpu-1gb", instanceCount: 3,});Source:
packages/digitalocean/src/Cron.ts
Run an Effect on a cron schedule inside a DigitalOcean.App.
- Deploy-time: adds an App Platform
SCHEDULEDjob to the host App. The job runs the App’s own image, with its env and bindings, on the schedule. - Runtime: the job’s container runs the handler once and exits, so App Platform records the run as succeeded or failed. The App’s web service never runs the handler.
App Platform runs a schedule at most every 15 minutes. Requires
CronLive provided on the App’s Effect.
cron: Declare a schedule
Section titled “cron: Declare a schedule”Clean up every night at 03:00 UTC
export default class Api extends DigitalOcean.App<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { yield* DigitalOcean.cron("0 3 * * *", () => Effect.log("nightly cleanup")); return { fetch: Effect.succeed(HttpServerResponse.text("ok")) }; }).pipe(Effect.provide(DigitalOcean.CronLive)),) {}A schedule in a time zone
yield* DigitalOcean.cron("0 9 * * 1-5", () => Effect.log("weekday report"), { timeZone: "Europe/Berlin",});