new·Earn with mozg — 20% of every monthSend somebody here and take a fifth of every plan payment they make, for as long as they keep paying — not a bounty on the first invoice. Your handle is the link, the window is thirty days, and the commission lands on your balance the second they pay. Free to join: if you have signed in, you already have the link. mozg.sh/earnall news →
mozg.beta
Sign in

Temporal · Develop · all subjects

nexus caller

19 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Nexus Python SDK - calling from workflow

Use workflow.create_nexus_client() to create a Nexus client in a caller Workflow. Call execute_operation() to start an operation and wait for the result in one call, or start_operation() to get an operation handle and await it separately. Example: nexus_client = workflow.create_nexus_client(service=MyNexusService, endpoint=NEXUS_ENDPOINT); result = await nexus_client.execute_operation(MyNexusService.my_sync_operation, MyInput(name))

Nexus Python SDK - workflow imports with unsafe imports_passed_through

Import Nexus service definitions and types into a Workflow using workflow.unsafe.imports_passed_through(). This allows the Workflow to import types defined outside the workflow module. Example: with workflow.unsafe.imports_passed_through(): from hello_nexus.service import MyInput, MyNexusService, MyOutput

Nexus Operation execution flow across Namespaces

When a caller Workflow invokes a Nexus Operation, the request flows from the caller Workflow through the Nexus Endpoint to the handler Worker, which starts or executes the corresponding Workflow or logic, and returns the result back to the caller. Namespaces provide isolation between the caller and handler sides. The Nexus Web UI shows NexusOperationScheduled, NexusOperationStarted, and NexusOperationCompleted events in the Event history.

Create Nexus Service client in caller Workflow

Use createNexusServiceClient() within a Workflow to create a client bound to a Nexus Service and Endpoint. Call executeOperation() with the operation name, input data, and options like scheduleToCloseTimeout to invoke the operation and wait for the result.

Nexus TypeScript quickstart example: caller Workflow

import { proxyActivities, createNexusServiceClient } from '@temporalio/workflow'; import type * as activities from './activities'; import { sayHelloService } from './service'; const { greet } = proxyActivities<typeof activities>({ startToCloseTimeout: '1 minute', }); export async function example(name: string): Promise<string> { return await greet(name); } const NEXUS_ENDPOINT = 'my-nexus-endpoint-name'; export async function callerWorkflow(name: string): Promise<string> { const nexusClient = createNexusServiceClient({ service: sayHelloService, endpoint: NEXUS_ENDPOINT, }); return await nexusClient.executeOperation('sayHello', { name }, { scheduleToCloseTimeout: '10s' }); }

Nexus TypeScript quickstart example: caller Workflow execution

import { randomUUID } from 'crypto'; import { Connection, Client } from '@temporalio/client'; import { NativeConnection, Worker } from '@temporalio/worker'; import { callerWorkflow } from './workflows'; const CALLER_TASK_QUEUE = 'my-caller-task-queue'; const NAMESPACE = 'my-caller-namespace'; async function main() { const clientConnection = await Connection.connect({ address: 'localhost:7233', }); const client = new Client({ connection: clientConnection, namespace: NAMESPACE, }); const workerConnection = await NativeConnection.connect({ address: 'localhost:7233', }); try { const worker = await Worker.create({ connection: workerConnection, namespace: NAMESPACE, taskQueue: CALLER_TASK_QUEUE, workflowsPath: require.resolve('./workflows'), }); await worker.runUntil(async () => { const result = await client.workflow.execute(callerWorkflow, { args: ['Temporal'], workflowId: `caller-workflow-${randomUUID()}`, taskQueue: CALLER_TASK_QUEUE, }); console.log('Workflow result:', result); }); } finally { await workerConnection.close(); } } main().catch((err) => { console.error(err); process.exit(1); });

Create NexusServiceClient with client.nexus.createServiceClient()

To execute a Standalone Nexus Operation, create a NexusServiceClient using client.nexus.createServiceClient() bound to a specific Nexus Endpoint and Service. The endpoint must be pre-created on the server.

executeOperation() waits for Operation to complete

executeOperation() waits for the Operation to complete and returns the result. It requires the id parameter. scheduleToCloseTimeout is optional and defaults to the maximum allowed by the Temporal server.

startOperation() returns NexusOperationHandle

startOperation() returns a NexusOperationHandle for both synchronous and asynchronous Operations. Use NexusOperationHandle.result() to wait until the Operation completes and retrieve its result.

Example: Execute Standalone Nexus Operation

const nexusClient = client.nexus.createServiceClient({ endpoint: ENDPOINT_NAME, service: myNexusService, }); const echoResult = await nexusClient.executeOperation( myNexusService.operations.echo, { message: 'hello' }, { id: `echo-${nanoid()}`, scheduleToCloseTimeout: '10s', }, );

Example: Start operation and get result with NexusOperationHandle

const handle = await nexusClient.startOperation( myNexusService.operations.hello, { name: 'World' }, { id: `hello-${nanoid()}`, scheduleToCloseTimeout: '10s', }, ); const helloResult = await handle.result(); console.log(helloResult.greeting);

List Standalone Nexus Operations with client.nexus.list()

Use client.nexus.list() to list Standalone Nexus Operation Executions that match a List Filter query. The result is an async iterator that yields operation metadata entries. client.nexus.list() is called on the base Client, not on the NexusServiceClient. The query parameter accepts List Filter syntax.

Example: List Nexus Operations

const query = `Endpoint = "${ENDPOINT_NAME}"`; for await (const op of client.nexus.list({ query })) { console.log( `OperationId: ${op.operationId},`, `Operation: ${op.operation},`, `Status: ${op.status}`, ); }

Count Standalone Nexus Operations with client.nexus.count()

Use client.nexus.count() to count Standalone Nexus Operation Executions that match a List Filter query. client.nexus.count() is called on the base Client, not on the NexusServiceClient.

Example: Count Nexus Operations

const query = `Endpoint = "${ENDPOINT_NAME}"`; const count = await client.nexus.count(query); console.log(`Total Nexus operations: ${count.count}`);

Execute Nexus Operation via CLI

Execute a Standalone Nexus Operation using: ./temporal nexus operation execute --namespace my-caller-namespace --endpoint my-nexus-endpoint --service myNexusService --operation echo --operation-id my-echo-op --input '{"message":"hello"}'

Get Nexus Operation result via CLI

Wait for a Nexus Operation result by Operation ID using: ./temporal nexus operation result --namespace my-caller-namespace --operation-id my-echo-op

List Nexus Operations via CLI

List Standalone Nexus Operations using: ./temporal nexus operation list --namespace my-caller-namespace --query 'Endpoint = "my-nexus-endpoint"'

Count Nexus Operations via CLI

Count Standalone Nexus Operations using: ./temporal nexus operation count --namespace my-caller-namespace --query 'Endpoint = "my-nexus-endpoint"'

Give your agent this brain