Skip to content

GCP.CloudScheduler reference

Source: src/GCP/CloudScheduler/Job.ts

A Cloud Scheduler job that invokes an HTTP, Pub/Sub, or App Engine target on a cron schedule.

Jobs have no labels field, so ownership rests on the deterministic job name: read reports a job it finds without prior state as unowned (adopt it with --adopt). Name and location are immutable; changing either replaces the job.

Generated name, yearly HTTP GET

const ping = yield* GCP.CloudScheduler.Job("Ping", {
schedule: "0 0 1 1 *",
paused: true,
httpTarget: {
uri: "https://example.com/",
httpMethod: "GET",
},
});

Named job with retries and a POST body

const notify = yield* GCP.CloudScheduler.Job("Notify", {
jobId: "order-notify",
location: "us-central1",
schedule: "every 15 minutes",
timeZone: "America/Chicago",
description: "fan out order events",
retryConfig: { retryCount: 3, minBackoffDuration: "10s" },
httpTarget: {
uri: "https://example.com/hooks/orders",
httpMethod: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ source: "scheduler" }),
},
});

Pub/Sub target

const tick = yield* GCP.CloudScheduler.Job("Tick", {
schedule: "0 * * * *",
pubsubTarget: {
topicName: topic.name,
data: "tick",
},
});

Source: src/GCP/CloudScheduler/PauseJob.ts

Runtime binding for Cloud Scheduler jobs.pause.

Bind this operation to a Job in a Function/Action init phase. Provide PauseJobHttp.

Grants roles/cloudscheduler.admin on the project: it is the only predefined role with cloudscheduler.jobs.pause, and Cloud Scheduler has neither per-job IAM policies nor IAM Conditions on resource.name.

const pauseJob = yield* GCP.CloudScheduler.PauseJob(ping);
yield* pauseJob();

Source: src/GCP/CloudScheduler/PauseJobHttp.ts Kind: Layer · Provides: GCP.CloudScheduler.PauseJob

HTTP implementation of PauseJob.

Grants roles/cloudscheduler.admin on the project because it is the only predefined role with cloudscheduler.jobs.pause, and Cloud Scheduler supports neither per-job IAM policies nor IAM Conditions on resource.name.

Source: src/GCP/CloudScheduler/ResumeJob.ts

Runtime binding for Cloud Scheduler jobs.resume.

Bind this operation to a Job in a Function/Action init phase. Provide ResumeJobHttp.

Grants roles/cloudscheduler.admin on the project: it is the only predefined role with cloudscheduler.jobs.enable, and Cloud Scheduler has neither per-job IAM policies nor IAM Conditions on resource.name.

const resumeJob = yield* GCP.CloudScheduler.ResumeJob(ping);
yield* resumeJob();

Source: src/GCP/CloudScheduler/ResumeJobHttp.ts Kind: Layer · Provides: GCP.CloudScheduler.ResumeJob

HTTP implementation of ResumeJob.

Grants roles/cloudscheduler.admin on the project because it is the only predefined role with cloudscheduler.jobs.enable, and Cloud Scheduler supports neither per-job IAM policies nor IAM Conditions on resource.name.

Source: src/GCP/CloudScheduler/RunJob.ts

Runtime binding for Cloud Scheduler jobs.run.

Forces an immediate dispatch even if the job is already running. Bind this operation to a Job in a Function/Action init phase. Provide RunJobHttp.

const runJob = yield* GCP.CloudScheduler.RunJob(ping);
yield* runJob();

Source: src/GCP/CloudScheduler/RunJobHttp.ts Kind: Layer · Provides: GCP.CloudScheduler.RunJob

HTTP implementation of RunJob.

Source: src/GCP/CloudScheduler/ScheduleEventSource.ts

Event source that invokes the hosting compute on a Cloud Scheduler schedule — the “cron handler” DX.

The HTTP-host implementation is GCP.Run.ScheduleEventSource (GCP.Function / GCP.Run.Service, GCP.CloudFunctions.Function): it creates a Cloud Scheduler job that POSTs to the host with an OIDC token for the host’s runtime service account, grants that account roles/run.invoker on the host, and verifies the token on every invocation. A failed handler answers 500 and the job’s retry policy applies.

Consume it through consumeSchedule.

Nightly cleanup on a Cloud Run service

export class Api extends GCP.Function<Api>()(
"Api",
{ main: import.meta.url },
Effect.gen(function* () {
yield* GCP.CloudScheduler.consumeSchedule(
"NightlyCleanup",
{ schedule: "0 3 * * *", timeZone: "America/New_York" },
(event) => Effect.log(`cleanup scheduled for ${event.scheduleTime}`),
);
}).pipe(Effect.provide(GCP.Run.ScheduleEventSource)),
) {}

Pass a fixed payload

yield* GCP.CloudScheduler.consumeSchedule(
"Digest",
{ schedule: "every 1 hours", body: JSON.stringify({ kind: "digest" }) },
(event) => sendDigest(JSON.parse(event.body ?? "{}")),
);