This workflow I’m executing as a cron workflow (not necessarily relevant). My second child workflow sleeps for a long period (3 mins). What I want to happen is that if this parent workflow is cancelled, I would still like the child workflow to complete. I read that PARENT_CLOSE_POLICY_ABANDON would prevent the cancellation being passed down, but in practice the child workflow cancels.
Is this because the workflow context that I’m passing in is getting cancelled? Should I be passing in a new workflow context?
I read this solution, and it isn’t exactly what I’m looking for. This is starting an async workflow, I want to start a workflow synchronously that won’t transfer the cancellation down if the parent is cancelled. If this isn’t possible, then I suppose an asynchronous workflow will do.
If you want to abandon, why wait for the child workflow execution result? Instead of .Get() consider .GetChildWorkflowExecution().Get() which will inform you of child workflow start but not complete.
If your only goal is to not have the context cancellation propagate, yes, you need a new context + abandon. See NewDisconnectedContext. But your code as is will still wait on child workflow completion, so you’ll have essentially swallowed and ignored the cancellation if you wait on a child workflow’s result regardless of cancellation sent (which is sometimes desirable for a short period of time e.g. in cleanup cases, but then you should still return the original cancel error so the parent can properly be marked cancel).
The primary reason that I don’t want the purely abandon is that the parent context is being run as a cron workflow. I want the recurring workflow to be cancellable, but I want the child workflow to finish its execution. I believe you describe exactly what I’m hoping for in that, I want the cancellation to be swallowed until the child finishes. This issue is resolvable with schedules (which I can’t wait for), but not with cron workflows.
The solution I ultimately went with is creating an additional workflow that is solely responsible for the executing the child task. This additional top-level workflow is given the cron schedule and the child workflow is then executed entirely asynchronously as described above. It can then be cancelled, thus cancelling the schedule, but also ensuring that and child workflow finishes its execution.