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_run_id_plugin 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 CloudRunIdPlugin Set a Temporal client's identity from Google Cloud Run instance metadata.
Class GoogleCloudRunMetadata Identifying metadata for the current Google Cloud Run instance.
Function get_google_cloud_run_metadata Read metadata identifying the current Google Cloud Run instance.
Constant CLOUD_RUN_METADATA_URL 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:floatTimeout, in seconds, for the request to the metadata server.
metadata_url:strURL of the Cloud Run metadata server endpoint that returns the instance id.
getenv:Callable[[str], str]Callable used to look up environment variables. Defaults to os.environ.get and exists primarily for testing.
Returns
GoogleCloudRunMetadataA GoogleCloudRunMetadata describing the current instance.
Raises
RuntimeErrorIf the metadata server cannot be reached, which usually means the process is not running on a Cloud Run worker pool or service.
CLOUD_RUN_METADATA_URL: str = (source)

Default Cloud Run metadata server endpoint returning the unique instance id.

Value
'http://metadata.google.internal/computeMetadata/v1/instance/id'