一键导入
resonate-gcp-deployments-typescript
Deploy Resonate TypeScript workers to Google Cloud Functions (Gen 2) using the GCP shim and connect them to a Resonate Server.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Deploy Resonate TypeScript workers to Google Cloud Functions (Gen 2) using the GCP shim and connect them to a Resonate Server.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Conceptual introduction to durable execution — what it is, why you'd want it, and the tradeoffs between rolling your own (just your DB) versus using a framework like Resonate. Read this BEFORE picking an implementation. For the Resonate SDK's concrete Context API (ctx.run, ctx.sleep, ctx.promise, structured concurrency), use the per-SDK skill for your language — resonate-basic-durable-world-usage-{typescript,python,rust,go}.
Advanced reasoning bridge between the Resonate specification (resonatehq/resonate-specification) and the Resonate TypeScript SDK. Use when mapping spec concepts (processes, executions, promises, coordination, recovery) to concrete SDK patterns and when validating correctness, durability, and failure semantics.
Core patterns for using Resonate Client APIs in the Ephemeral World - initialization, registration, top-level invocations, promise management, and dependency injection. Use this for application entry points and orchestration code outside of durable functions.
Debug and troubleshoot Resonate applications using the Java SDK. Use when investigating stuck or never-resuming workflows, duplicated side effects after replay, untyped-handle decode surprises (Integer vs Long), CLI positional-argument arity mismatches, the detached by-name-only constraint, Java 21 / virtual-thread requirements, rejected-promise error handling, or r.stop() silently killing a live worker. Verified against the resonatehq-examples/*-java repos and develop/java.mdx (docs PR
Use when writing the body of a Java durable function — any method registered with r.register or passed as a method reference to ctx.run. Core patterns for the Context API surface — the Context first-parameter signature, Context APIs (ctx.run, ctx.rpc, ctx.sleep, ctx.promise, ctx.detached, ResonateFuture.await), per-call options via ctx.options(new Opts()), context accessors (ctx.info), type-keyed dependency injection (ctx.getDependency), retry policies, dispatch-then-await fan-out, and the replay model. For multi-stage sleep timers, countdowns, and the cron Schedule API see resonate-durable-sleep-scheduled-work-java. Requires Java 21+ (virtual threads). Verified against the resonatehq-examples/*-java repos and develop/java.mdx (docs PR
Use when writing Java code in main(), an HTTP handler, or any entry point that launches or coordinates Resonate workflows from the ephemeral world (the Client API surface, not code inside a durable function). Core patterns for the Resonate Java SDK's Client APIs — building a Resonate instance with the fluent builder (or new Resonate() for local mode), registering durable functions via method references, invoking them top-level with r.run, dispatching remotely with r.rpc, reconnecting to an existing execution with r.get, reading typed vs untyped handles, the promises and schedules sub-clients, per-call options, and stop semantics. Requires Java 21+ (virtual threads). Verified against example-hello-world-java / example-countdown-java / example-recursive-factorial-java and develop/java.mdx (docs PR
| name | resonate-gcp-deployments-typescript |
| description | Deploy Resonate TypeScript workers to Google Cloud Functions (Gen 2) using the GCP shim and connect them to a Resonate Server. |
| license | Apache-2.0 |
Deploy a TypeScript Resonate worker as an HTTP-triggered Google Cloud Function that talks to a Resonate Server.
You (the agent) should obtain or be given:
GCP_PROJECT_ID – Google Cloud project IDGCP_REGION – GCP region (e.g. us-central1)FUNCTION_NAME – Name for the Cloud Function (e.g. countdown-workflow)RESONATE_SERVER_URL – Public URL of the Resonate Server HTTP API (e.g. https://resonate-server-...a.run.app) [Deploy server]WORKER_ENTRY – TS entry file exposing a handler function (typically index.ts)Prerequisites in the project environment:
gcloud CLI authenticated for GCP_PROJECT_IDnpm or compatible package manager@resonatehq/gcp) to the worker project. [Serverless workers]RESONATE_URL env var for the function so it can reach the Resonate Server. [Deploy Cloud Function]gcloud functions deploy (Gen 2, HTTP trigger).resonate-state-bus-pattern-typescript for the pattern (Firestore onSnapshot is the lightest GCP option).For deploying the Resonate Server itself on GCP (Cloud Run + Cloud SQL), see resonate-server-deployment-cloud-run.
From the worker project root:
npm install @resonatehq/gcp
Use the Resonate class from the GCP package instead of the base SDK. [Serverless workers]
Create index.ts (or use the given WORKER_ENTRY) with this pattern:
import { Resonate } from "@resonatehq/gcp";
import type { Context } from "@resonatehq/sdk";
// Example durable workflow
function* countdown(ctx: Context, count: number, delayMs: number) {
for (let i = count; i > 0; i--) {
// Replace with your real work; this mirrors the standard countdown example
yield* ctx.run((c: Context, j = i) => {
console.log(`Countdown: ${j}`);
});
yield* ctx.sleep(delayMs);
}
console.log("Done!");
}
// Instantiate Resonate using the GCP shim
const resonate = new Resonate();
// Register the durable function (name "countdown" is just an example)
resonate.register("countdown", countdown);
// Export an HTTP handler compatible with Cloud Functions Gen 2
export const handler = resonate.handlerHttp();
This pattern is the same as the documented GCP shim usage, just with a concrete example function. [Serverless workers; Countdown worker structure]
RESONATE_URL points at the serverThe worker must know where the Resonate Server is. Use the RESONATE_URL environment variable in the function deployment, pointing to the server HTTP base URL. [Cloud Function deploy]
Example value:
RESONATE_URL=https://resonate-server-<hash>-<region>.a.run.app
From the worker project root:
gcloud functions deploy <FUNCTION_NAME> \
--gen2 \
--region=<GCP_REGION> \
--runtime=nodejs22 \
--source=. \
--entry-point=handler \
--trigger-http \
--allow-unauthenticated \
--set-env-vars=RESONATE_URL=<RESONATE_SERVER_URL>
Example (mirrors the docs, with a generic name): [Cloud Function deploy]
gcloud functions deploy countdown-workflow \
--gen2 \
--region=us-central1 \
--runtime=nodejs22 \
--source=. \
--entry-point=handler \
--trigger-http \
--allow-unauthenticated \
--set-env-vars=RESONATE_URL=https://resonate-server-...a.run.app
From the deploy output, capture the Function URL (under serviceConfig.uri or url). [Cloud Function deploy]
If needed, use the worker URL as the --target when invoking a durable function through the Resonate Server. [Trigger countdown]
Example:
resonate invoke countdown-workflow-1 \
--func countdown \
--arg 5 \
--arg 60000 \
--server <RESONATE_SERVER_URL> \
--target <FUNCTION_URL>
Where:
--server is the Resonate Server URL (same as RESONATE_SERVER_URL).--target is the Cloud Function URL from the previous step.Timeout note: the default promise timeout is short. For long-running or forever-loop workflows, set --timeout explicitly (e.g. --timeout 720h for a 30-day horizon). A workflow whose timeout lapses will not be resumed.
Pitfall: if worker logs show fetch failed / connection_error, the server is probably returning task URLs pointing at http://localhost:8001. Set --server-url on the server side — see resonate-server-deployment-cloud-run or resonate-server-deployment.
Cloud Functions are short-lived — they can't hold an SSE or WebSocket connection for the life of a durable workflow. The durable pattern is to write workflow state to an external realtime bus (e.g. Firestore) and subscribe from the browser.
This is its own pattern, covered end-to-end in resonate-state-bus-pattern-typescript. Firestore + onSnapshot is the lightest GCP option; the same shape works with Supabase Realtime, Pub/Sub, or any DB with change feeds.
handler compatible with Resonate.example-chess-hero-gcp-ts — end-to-end: worker on Cloud Functions Gen 2, server on Cloud Run (resonate-server-deployment-cloud-run), output streamed to a browser via resonate-state-bus-pattern-typescript.