temporal icon indicating copy to clipboard operation
temporal copied to clipboard

Start orphan child workflow from workflow

Open sytranvn opened this issue 1 year ago • 2 comments
trafficstars

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.

ParentWorkflow ------------------------------------------------------x
                 |                  |    |                       |
                 ---ChildWorkflow----    ---- other activities ---
                                   |
                                   --- WrapupWorkflow --x

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 call start_workflow. Like this.

ParentWorkflow -----------------------------------------------------------------------------x
                 |                                         |  |                       |
                 ---ChildWorkflow--------------------------|   ---- other activities --
                                  |                        |        
                                  -- start_wrapup_activity-
                                   |
                                   --- client.start_workflow(WrapupWorkflow) --x

Describe the solution you'd like Support starting an orphan workflow from inside workflow and forget it.

   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 might not applicable to execute_workflow though.

sytranvn avatar Apr 23 '24 07:04 sytranvn

Hi @sytranvn! Could you take a look at https://docs.temporal.io/workflows#parent-close-policy - specifically Abandon - and let me know if that solves your problem?

stephanos avatar Apr 26 '24 21:04 stephanos

@stephanos , I use ABANDON as parameter for start_child_workflow. But the child is still terminated as soon as Parent completes. Here's the code https://github.com/sytranvn/abandon-child

Parent's events image
{
  "eventId": "1",
  "eventTime": "2024-04-29T01:53:39.274145300Z",
  "eventType": "WorkflowExecutionStarted",
  "version": "0",
  "taskId": "7342055",
  "workerMayIgnore": false,
  "workflowExecutionStartedEventAttributes": {
    "workflowType": {
      "name": "Parent"
    },
    "parentWorkflowNamespace": "",
    "parentWorkflowNamespaceId": "",
    "parentWorkflowExecution": null,
    "parentInitiatedEventId": "0",
    "taskQueue": {
      "name": "hello-activity-task-queue",
      "kind": "Normal",
      "normalName": ""
    },
    "input": null,
    "workflowExecutionTimeout": null,
    "workflowRunTimeout": null,
    "workflowTaskTimeout": "10s",
    "continuedExecutionRunId": "",
    "initiator": "Unspecified",
    "continuedFailure": null,
    "lastCompletionResult": null,
    "originalExecutionRunId": "218527ab-72a1-4602-8983-49652953e7ef",
    "identity": "87986@sytd",
    "firstExecutionRunId": "218527ab-72a1-4602-8983-49652953e7ef",
    "retryPolicy": null,
    "attempt": 1,
    "workflowExecutionExpirationTime": null,
    "cronSchedule": "",
    "firstWorkflowTaskBackoff": "0s",
    "memo": null,
    "searchAttributes": null,
    "prevAutoResetPoints": null,
    "header": null,
    "parentInitiatedEventVersion": "0",
    "workflowId": "hello-activity-workflow-id",
    "sourceVersionStamp": null
  }
}
Child's events Screenshot 2024-04-29 at 09 02 44 Screenshot 2024-04-29 at 09 01 59
{
  "eventId": "1",
  "eventTime": "2024-04-29T01:53:39.343533866Z",
  "eventType": "WorkflowExecutionStarted",
  "version": "0",
  "taskId": "7341866",
  "workerMayIgnore": false,
  "workflowExecutionStartedEventAttributes": {
    "workflowType": {
      "name": "Child"
    },
    "parentWorkflowNamespace": "default",
    "parentWorkflowNamespaceId": "143c04ed-6dba-4d45-b992-f9b71480ffcd",
    "parentWorkflowExecution": {
      "workflowId": "hello-activity-workflow-id",
      "runId": "218527ab-72a1-4602-8983-49652953e7ef"
    },
    "parentInitiatedEventId": "5",
    "taskQueue": {
      "name": "hello-activity-task-queue",
      "kind": "Normal",
      "normalName": ""
    },
    "input": null,
    "workflowExecutionTimeout": null,
    "workflowRunTimeout": "0s",
    "workflowTaskTimeout": "10s",
    "continuedExecutionRunId": "",
    "initiator": "Unspecified",
    "continuedFailure": null,
    "lastCompletionResult": null,
    "originalExecutionRunId": "63529741-0faa-4673-84b0-1099ac50fa29",
    "identity": "",
    "firstExecutionRunId": "63529741-0faa-4673-84b0-1099ac50fa29",
    "retryPolicy": null,
    "attempt": 1,
    "workflowExecutionExpirationTime": null,
    "cronSchedule": "",
    "firstWorkflowTaskBackoff": "0s",
    "memo": {
      "fields": {}
    },
    "searchAttributes": {
      "indexedFields": {}
    },
    "prevAutoResetPoints": null,
    "header": {
      "fields": {}
    },
    "parentInitiatedEventVersion": "0",
    "workflowId": "1ea52de8-f94e-437a-8026-67bc9525d3e4",
    "sourceVersionStamp": null
  }
}

sytranvn avatar Apr 29 '24 02:04 sytranvn