package documentation
Run Temporal workers on Google Cloud Run.
CloudRunIdPlugin reads Cloud Run instance metadata (from a worker pool or a service) and
sets the client identity from the Cloud Run instance.
Quick start:
import asyncio
from temporalio.client import Client
from temporalio.contrib.gcp.cloud_run.id import CloudRunIdPlugin
from temporalio.worker import Worker
async def main() -> None:
# Install the plugin on the client; it propagates to workers automatically.
client = await Client.connect(
"localhost:7233",
plugins=[CloudRunIdPlugin()],
)
worker = Worker(
client,
task_queue="my-task-queue",
workflows=[MyWorkflow],
activities=[my_activity],
)
await worker.run()
asyncio.run(main())
| Module | _cloud |
Plugin setting a Temporal client's identity from Google Cloud Run instance metadata. |
| Module | _metadata |
Read Google Cloud Run instance metadata for Temporal worker configuration. |
From __init__.py:
| Class | |
Set a Temporal client's identity from Google Cloud Run instance metadata. |
| Class | |
Identifying metadata for the current Google Cloud Run instance. |
| Function | get |
Read metadata identifying the current Google Cloud Run instance. |
| Constant | CLOUD |
Default Cloud Run metadata server endpoint returning the unique instance id. |
def get_google_cloud_run_metadata(*, timeout:
float = 2.0, metadata_url: str = CLOUD_RUN_METADATA_URL, getenv: Callable[ [ str], str] = os.environ.get) -> GoogleCloudRunMetadata:
(source)
¶
Read metadata identifying the current Google Cloud Run instance.
Resolves the worker pool name from CLOUD_RUN_WORKER_POOL (Cloud Run worker pools), falling back to the service name (K_SERVICE, Cloud Run services), and the revision from CLOUD_RUN_REVISION falling back to K_REVISION. The unique instance id is fetched from the Cloud Run metadata server with a single synchronous HTTP GET. Intended to be called once at worker startup.
| Parameters | |
timeout:float | Timeout, in seconds, for the request to the metadata server. |
metadatastr | URL of the Cloud Run metadata server endpoint that returns the instance id. |
getenv:Callable[ | Callable used to look up environment variables. Defaults to os.environ.get and exists primarily for testing. |
| Returns | |
GoogleCloudRunMetadata | A GoogleCloudRunMetadata describing the current instance. |
| Raises | |
RuntimeError | If the metadata server cannot be reached, which usually means the process is not running on a Cloud Run worker pool or service. |