简体   繁体   中英

Azure Durable functions Terminate doesn't work

I need to run background process which runs for longtime(30mins - 2hours), currently i am using azure functionapp(Premium plan) for this & it works fine. now i have to add a feature for cancelling this process in between, whenever user wants terminate process. So i figured out there is way to do in Durable functions and i tried sample, but even after i invoke Terminate function, the ongoing orchestrator process still runs and doesn't stop & also it re-invokes the orchestrator again. I am not sure what is wrong. below is the code snippet.

  const client = df.getClient(context);
    var instanceId = '';
    //Check if queryparam has instanceid, if yes terminate process else create new
    if (req.params.id != "0") {
       await client.terminate(req.params.id,"test");
    } else {
        instanceId = await client.startNew(req.params.functionName, undefined, req.body);
    }
    context.log(`Started orchestration with ID = '${instanceId}'.`);
    return client.createCheckStatusResponse(context.bindingData.req, instanceId);

Based on documentation check the Functions versions because you must have different types of attributes:

for Durable Functions 2.x. For Durable Functions 1.x, you must use OrchestrationClient attribute instead of the DurableClient attribute, and you must use the DurableOrchestrationClient parameter type instead of IDurableOrchestrationClient

If we read more we can understand that the function will not just end sudden:

A terminated instance will eventually transition into the Terminated state. However, this transition will not happen immediately. Rather, the terminate operation will be queued in the task hub along with other operations for that instance. You can use the instance query APIs to know when a terminated instance has actually reached the Terminated state.

Instance termination doesn't currently propagate. Activity functions and sub-orchestrations run to completion, regardless of whether you've terminated the orchestration instance that called them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM