Hi! I’m using Temporal with the Typescript SDK. In my use case I have an parent workflow who is listening for a signal that comes with an id of the user who cancelled the workflow.
That parent workflow also has a child workflow who creates some records in my DB. If there’s a cancellation, I’d like to be able to have it mark the records as cancelled and attach the id of who cancelled them.
From the docs I can’t figure out the best way to do this as I don’t see how you could attach any information when I call cancel on the cancellation scope in the parent workflow that the child workflow would be able to get access to. What’s the best way to do this?
1 Like
You could catch the cancelation and send a signal to the child (untested).
export async function parentWorkflow() {
let cancelIdentity = "";
workflow.setHandler(someSignal, ({ identity }) => {
cancelIdentity = identity;
});
// Prevent workflow cancelation from propagating.
await workflow.CancellationScope.nonCancellable(async () => {
// Create another scope that we can control cancelling.
await workflow.CancelationScope.cancellable(async () => {
const handle = workflow.startChild(....);
return await Promise.race([
(async () => {
await workflow.condition(() => cancelIdentity !== "");
await handle.signal(someOtherSignal, cancelIdentity);
workflow.CancellationScope.current().cancel();
return await handle.result();
})(),
handle.result(),
]);
});
})
}
I am also having this issue. I would love to have support for passing args to cancel(). It would make things a lot easier. The args would be available on the error object.