docs(sdk): add invoke operation page#164
Conversation
| Invoke operations let you call other Lambda functions from within your durable function. You can invoke both durable functions and regular on-demand Lambda functions. This enables function composition, where you break complex workflows into smaller, reusable functions. The calling function suspends while the invoked function executes, and resumes when the result is available. | ||
|
|
||
| Use invoke operations to: | ||
| - Decompose complex workflows into manageable functions |
There was a problem hiding this comment.
haha, "decompose" is a very particular usage here 🧟 .
"Modularize"?
|
|
||
| **Raises:** | ||
| - `CallableRuntimeError` - If the invoked function fails or times out | ||
| - `SuspendExecution` - When the operation is first started or still in progress (internal) |
There was a problem hiding this comment.
consumer doesn't see this
|
|
||
| **serdes_payload** - Custom serialization/deserialization for the payload sent to the invoked function. If not provided, uses JSON serialization. | ||
|
|
||
| **serdes_result** - Custom serialization/deserialization for the result returned by the invoked function. If not provided, uses JSON serialization. |
There was a problem hiding this comment.
since we have the types:
timeout: Duration = field(default_factory=Duration)
serdes_payload: SerDes[P] | None = None
serdes_result: SerDes[R] | None = None
tenant_id: str | None = None
There was a problem hiding this comment.
timeout: Maximum duration to wait for the invoked function to complete.
Default is no timeout. Use this to prevent long-running invocations
from blocking execution indefinitely.
serdes_payload: Custom serialization/deserialization for the payload
sent to the invoked function. If None, uses default JSON serialization.
serdes_result: Custom serialization/deserialization for the result
returned from the invoked function. If None, uses default JSON serialization.
tenant_id: Optional tenant identifier for multi-tenant isolation.
If provided, the invocation will be scoped to this tenant.
|
|
||
| **Consider cost implications** - Each invoke operation triggers a separate Lambda invocation, which has cost implications. | ||
|
|
||
| **Mix durable and on-demand functions** - You can invoke both durable and regular Lambda functions. Use durable functions for complex workflows and on-demand functions for simple operations. |
There was a problem hiding this comment.
this is actually an interesting/good design pattern!
The orchestrator could be Durable, and then compose regular on-demand functions. The orchestrator provides the durability for the results of the invoked on-demand functions without needing to provide the durabiity on the invoked functions themselves.
|
|
||
| ```python | ||
| result1 = context.invoke("function-1", payload1) | ||
| result2 = context.invoke("function-2", result1) |
There was a problem hiding this comment.
the type of the return value is governed by the serdes_result.
|
Hey @yaythomas thanks for the feedback! it's ready to another review. |
closes #163
Description of changes:
This PR adds
docs/core/invoke.mddocumentation for invoke operations. The guide explains how to usecontext.invoke()to call other durable functions, including payload serialization, InvokeConfig options, and function composition patterns. It covers error handling for invoked functions, result handling, and a testing section showing how to verify invoke operations with test examples.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.