Skip to content

Support schedule triggers for Dart (Cloud Run) functions - #11223

Open
Ortes wants to merge 1 commit into
firebase:mainfrom
Fullphysio:dart-run-schedule-triggers
Open

Ortes wants to merge 1 commit into
firebase:mainfrom
Fullphysio:dart-run-schedule-triggers

Conversation

@Ortes

@Ortes Ortes commented Oct 2, 2026

Copy link
Copy Markdown

Description

Deploying a Dart function that uses firebase.scheduler.onSchedule fails: setTrigger() and deleteTrigger() throw Schedule triggers for Cloud Run functions are not supported yet. for platform: "run". The Cloud Run service is created first, so the deploy leaves a service with no Cloud Scheduler job.

This PR reuses the existing GCFv2 schedule path, since cloudscheduler.jobFromEndpoint() already handles run (HTTP target on endpoint.uri with an OIDC token):

  • setTrigger / deleteTrigger: run goes through upsertScheduleV2 / deleteScheduleV2.
  • createRunFunction / updateRunFunction: grant roles/run.invoker to the scheduler's service account (the endpoint's serviceAccount, else the default compute SA), as createV2Function / updateV2Function already do.
  • runv2.serviceFromEndpoint / endpointFromService: persist scheduleTrigger in the firebase-functions-metadata annotation. Without it, the existing service is read back as httpsTrigger, and the second deploy aborts with Changing from an HTTPS function to a scheduled function is not allowed.

Related: #10851 does the same for Firestore event triggers on Cloud Run. The two are independent; this one only touches schedule triggers.

Scenarios Tested

Unit tests added in fabricator.spec.ts and runv2.spec.ts.

Manually on a real project (europe-west3), with a Dart onSchedule(schedule: '*/2 * * * *') using timeZone and retryConfig:

  • First deploy creates the Cloud Run service, the Cloud Scheduler job (correct schedule, time zone, retry count, OIDC service account) and the run.invoker binding.
  • The job fires on schedule and on gcloud scheduler jobs run; the handler gets a 200 and the ScheduledEvent headers.
  • A second deploy with no change updates the service without the HTTPS-to-scheduled abort.
  • Changing timeZone / retryCount updates the job in place.
  • A throwing handler returns 500 and Cloud Scheduler retries exactly retryCount times.
  • Unauthenticated requests to the service URL get 403.
  • Removing the function from the codebase (and functions:delete) deletes both the service and the job.

Sample Commands

FIREBASE_CLI_EXPERIMENTS=dartfunctions firebase deploy --only functions

setTrigger/deleteTrigger threw for platform run. Reuse the v2 Cloud Scheduler
path (jobFromEndpoint already targets endpoint.uri with an OIDC token), grant
run.invoker to the scheduler service account on create and update, and persist
scheduleTrigger in the firebase-functions-metadata annotation so the next deploy
reads the service back as scheduled instead of HTTPS.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for deploying scheduled Dart functions (onSchedule) to Cloud Run. Key changes include updating the fabricator to manage schedule triggers and configure the run.invoker role for the scheduler's service account, as well as preserving schedule trigger metadata in Cloud Run service annotations for backend reconstruction. Corresponding unit tests and a changelog entry have been added. I have no feedback to provide as there are no review comments.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant