Add Google Cloud Run worker-identity sample - #356
Draft
seanbollin wants to merge 1 commit into
Draft
Conversation
Add a runnable sample that runs a long-lived Temporal Worker in a Google Cloud Run worker pool and uses temporalio.contrib.gcp.cloud_run to derive the worker identity and a PINNED Worker Deployment version from Cloud Run instance metadata. The sample registers a small greeting Workflow and Activity, reads TEMPORAL_ADDRESS / TEMPORAL_NAMESPACE / TEMPORAL_TASK_QUEUE (plaintext or, with TEMPORAL_API_KEY, Temporal Cloud over TLS), and runs until Cloud Run sends SIGTERM. The sample is standalone and excluded from the root project's build/lint/type tooling, mirroring the lambda_worker sample. The Cloud Run metadata helper is not released yet, so pyproject.toml pins temporalio to the local SDK checkout (../../sdk-python-2) on the cloud-run-worker-id branch; the README and Dockerfile note this must be dropped for a released (or git-pinned) temporalio once the helper ships. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a runnable Google Cloud Run worker pool sample under
gcp_cloud_run_worker_id/that uses the newtemporalio.contrib.gcp.cloud_runhelper to derive a worker identity (<instance_id>@<revision>) and a PINNED Worker Deployment version from Cloud Run instance metadata, then runs a long-lived Worker until Cloud Run sendsSIGTERM.worker.py— derives identity +worker_deployment_configfromget_google_cloud_run_metadata()and runs a versioned Worker.workflows.py/activities.py— a small greeting Workflow (PINNED versioning behavior) + Activity.settings.py— readsTEMPORAL_ADDRESS/TEMPORAL_NAMESPACE/TEMPORAL_TASK_QUEUE(plaintext), with optionalTEMPORAL_API_KEYfor Temporal Cloud (TLS).starter.py— starts a Workflow from a local machine.Dockerfile/.dockerignore— container build forgcloud run worker-pools deploy.README.md— explains Cloud Run worker pools and thegcloud run worker-pools deploy … --set-env-vars …flow.Structure mirrors the existing
lambda_workersample (standalone directory, ownpyproject.toml, excluded from the root project's build/lint/type tooling).Draft — depends on an unreleased helper
The Cloud Run metadata helper is not released yet (SDK PR: temporalio/sdk-python#1776). To keep this sample runnable,
pyproject.tomlpinstemporalioto a local path source (../../sdk-python-2) on thecloud-run-worker-idbranch. This[tool.uv.sources]override must be dropped (in favor of a releasedtemporalio) once the helper ships; the README and Dockerfile call this out. The local path is not available inside a Docker build context, so the container build must use a released or git-pinnedtemporalio(documented in theDockerfile).Note: directory naming vs. the Cloud Run OpenTelemetry sample
There is a separate in-flight Cloud Run effort that adds a
gcp_cloud_run/sample (OpenTelemetry plugin). To avoid a directory collision, this worker-identity sample is namedgcp_cloud_run_worker_id/. If both land, we may want to consolidate them under a singlegcp_cloud_run/sample (worker identity + OTel) or settle on a consistent naming scheme — flagging here for a maintainer decision before un-drafting.Verification
ruff check --select I(isort) andruff format --checkpass on the sample.🤖 Generated with Claude Code