dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

trigger one workflow from another workflow #204

Open dhiaayachi opened 3 weeks ago

dhiaayachi commented 3 weeks ago

I was wondering if it was possible to trigger one workflow using another workflow? For instance: can workflow A trigger workflow B and can workflow B access outputs from workflow A's activity?

We want to build two different workflows for two different teams that share the same temporal server

dhiaayachi commented 1 week ago

Thank you for your question!

Temporal does not currently support triggering one workflow from another directly. However, you can achieve similar functionality using Signals.

Workflow A can send a Signal to Workflow B with the information Workflow B needs to start its execution. Workflow B can then use this information to process its tasks.

Here's a simple example of how this might work:

Workflow A:

signalWorkflowB(input):
  emit signal "startWorkflowB" with payload input

Workflow B:

onSignal "startWorkflowB"(input):
  process tasks based on input

For more information on Signals, please refer to the Workflow Message Passing page.

dhiaayachi commented 1 week ago

Thanks for reaching out! It is definitely possible to trigger one workflow using another workflow. You can use child workflows to achieve this.

Here's how it works:

Let me know if you have any more questions!

dhiaayachi commented 1 week ago

Thanks for reaching out! You are right, it is possible to trigger one workflow from another. The Child Workflow Execution is a workflow execution spawned from another workflow. Workflow A can trigger Workflow B using the Child Workflow API. You can also access outputs from Workflow A's activity from Workflow B.

Workflow A would be the parent workflow, and Workflow B would be the child workflow. The parent workflow can monitor the child workflow's lifecycle and can wait for its completion or results. For example, you can wait for Workflow B to complete before proceeding with Workflow A or access the outputs from Workflow B.

There are two ways to start a Child Workflow Execution and return a handle to it, use startChild. For an example, check the code in child-workflows/src/workflows.ts.

You can learn more about child workflows and the Parent Close Policy to understand how a child workflow execution is terminated. You can find the implementation details for each SDK in the respective documentation.