Open dhiaayachi opened 2 months ago
This feature request addresses the need to start new workflows from within an existing workflow without the new workflow's lifetime being dependent on the parent.
Problem:
Currently, child workflows and activities in Temporal are tied to the parent workflow's lifetime. This requires additional steps, like calling an activity that uses a Temporal Client to start a new workflow. This adds complexity and can introduce potential race conditions if the parent workflow closes before the new workflow is fully started.
Example:
Consider a workflow that first executes a child workflow and then initiates a separate "wrap-up" workflow that should run at a later time. Using the current approach, the wrap-up workflow's execution is tied to the parent, leading to unnecessary waiting and potentially losing the wrap-up workflow if the parent completes prematurely.
Proposed Solution:
Introduce a new API function workflow.start_orphan_workflow
that allows a workflow to start a new workflow without coupling its lifetime to the parent. The function would accept the workflow definition, arguments, and optional options such as delay_start
for scheduling the new workflow at a later time.
Code Example:
workflow.start_orphan_workflow(
WrapupWorkflow.run,
"your retry policy argument",
delay_start=timedelta(days=1),
id="your-workflow-id",
task_queue="your-task-queue",
)
This new API call allows the parent workflow to start a new, independent workflow. The delay_start
option enables scheduling the workflow for a later execution.
Benefits:
Considerations:
execute_workflow
: The start_orphan_workflow
API call might not be applicable for the execute_workflow
function as it returns a handle to manage the workflow, which wouldn't be necessary for an orphan workflow.Reference:
This new functionality would be a valuable addition to the Temporal Python SDK, enabling developers to build more robust and efficient asynchronous workflows.
Thanks for raising this feature request!
Currently, Temporal doesn't directly support starting orphan workflows from within a workflow. The lifetime of child workflows and activities is indeed tied to the parent workflow.
However, you can achieve a similar outcome by using an activity to start the WrapupWorkflow
:
workflow.start_activity(
"start_wrapup_activity",
args=("your retry policy argument",),
delay_start=timedelta(days=1),
id="your-workflow-id",
task_queue="your-task-queue",
)
This approach allows you to decouple the WrapupWorkflow
from the parent workflow's lifetime and provides a workaround for your requirement.
Let us know if you have any further questions or if this solution meets your needs. We're always happy to help!
Thanks for your feature request!
Temporal currently does not have a dedicated start_orphan_workflow
API, but you can use the client.start_workflow
API to achieve the same functionality with minor adjustments. Here's how:
client.start_workflow(
WrapupWorkflow.run,
"your retry policy argument",
id="your-workflow-id",
task_queue="your-task-queue",
start_delay=timedelta(days=1)
)
This will start the WrapupWorkflow
with the specified delay, independent of the ParentWorkflow
.
This approach leverages Temporal's built-in scheduling capabilities to achieve the desired behavior.
Thanks for the feature request! Currently, Temporal does not support starting "orphan" child workflows that are not tied to the lifecycle of the parent workflow.
You can achieve similar behavior with a workaround:
await
its completion within the parent workflow. This will ensure that the parent workflow does not move forward until the child workflow completes. We understand the need for this feature, and we appreciate your feedback!
Is your feature request related to a problem? Please describe.
Ability to start new workflow from other workflow. But the new workflow's lifeftime does not depends on the other.
As in this diagram, after the ChildWorkflow complete its job, we want to return the result immediately to ParentWorkflow. The WrapupWorkflow only start the next day, and its result doesn't matter to the ParentWorkflow. Currently child workflow and activity lifetime depends on workflow. So I have to add additional steps to call an activity, which connects to
Client
and callstart_workflow
. Like this.Describe the solution you'd like Support starting an orphan workflow from inside workflow and forget it.
This might not applicable to
execute_workflow
though.