如何在azure持久函数中取消正在运行的触发器函数?

如何在azure持久函数中取消正在运行的触发器函数?,azure,azure-functions,azure-durable-functions,azure-function-async,Azure,Azure Functions,Azure Durable Functions,Azure Function Async,我正在尝试扇出、扇入模式。这是我的密码 [FunctionName("af_cancellation")] public static async Task<string> RunOrchestrator( [OrchestrationTrigger] DurableOrchestrationContext context, ILogger log) { var taskList = new List&

我正在尝试扇出、扇入模式。这是我的密码

[FunctionName("af_cancellation")]
        public static async Task<string> RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context, ILogger log)
        {

            var taskList = new List<Task<string>>();
            var tokenSource = new CancellationTokenSource();

            taskList.Add(context.CallActivityAsync<string>("af_cancellation_Hello", new { ct = tokenSource.Token, city = "Tokyo" }));
            taskList.Add(context.CallActivityAsync<string>("af_cancellation_Hello", new { ct = tokenSource.Token, city = "Seattle" }));
            taskList.Add(context.CallActivityAsync<string>("af_cancellation_Hello", new { ct = tokenSource.Token, city = "London" }));


            try
            {
                await Task.WhenAll(taskList);
            }
            catch (FunctionException)
            {
                log.LogError("trigger function failed");
                tokenSource.Cancel();
            }

            string output = "";
            foreach (var t in taskList)
            {
                output += t.Result;
            }
            return output;
        }
[函数名(“af_取消”)]
公共静态异步任务RunOrchestrator(
[OrchestrationTrigger]DurableOrchestrationContext上下文,ILogger日志)
{
var taskList=新列表();
var tokenSource=new CancellationTokenSource();
Add(context.CallActivityAsync(“af_cancellation_Hello”,new{ct=tokenSource.Token,city=“Tokyo”}));
Add(context.CallActivityAsync(“af_cancellation_Hello”,new{ct=tokenSource.Token,city=“西雅图”}));
Add(context.CallActivityAsync(“af_cancellation_Hello”,new{ct=tokenSource.Token,city=“London”}));
尝试
{
等待任务。WhenAll(任务列表);
}
捕获(函数异常)
{
log.LogError(“触发功能失败”);
tokenSource.Cancel();
}
字符串输出=”;
foreach(任务列表中的变量t)
{
输出+=t.结果;
}
返回输出;
}
如果任务列表中的任何任务引发异常,我想取消它们中的所有任务。我注意到的是等待任务。在前进之前,所有任务都完成了

下面是示例触发器函数

[FunctionName("af_cancellation_Hello")]
        public static string SayHello([ActivityTrigger] DurableActivityContext context, ILogger log)
        {
            var data = context.GetInput<dynamic>();
            var name = (string)data.city;
            // unable to de-serialize cancellation token here but we'll ignore that. 
            var ct = JsonConvert.DeserializeObject<CancellationToken>(data.ct);
            if (name != "London")
            {
                System.Threading.Thread.Sleep(1000 * 30);
            }
            else
            {
                System.Threading.Thread.Sleep(1000 * 10);
                throw new FunctionException("don't like london");
            }
            log.LogInformation($"Saying hello to {name}.");
            return $"Hello {name}!";
        }
[FunctionName(“af\u cancellation\u Hello”)]
公共静态字符串SayHello([ActivityTrigger]DurableActivityContext上下文,ILogger日志)
{
var data=context.GetInput();
变量名称=(字符串)data.city;
//无法在此处反序列化取消令牌,但我们将忽略它。
var ct=JsonConvert.DeserializeObject(data.ct);
如果(名称!=“伦敦”)
{
系统线程线程睡眠(1000*30);
}
其他的
{
系统线程线程睡眠(1000*10);
抛出新函数异常(“不喜欢伦敦”);
}
log.LogInformation($“向{name}打招呼”);
return$“Hello{name}!”;
}
我怎样才能做到这一点呢?

据我所知,这是不可能的。如果需要从其他成功的活动中撤消作业,则必须查看Saga模式并启动补偿活动

更多信息:


谢谢你的回答。我将尝试通过一个后台线程来实现它,该线程会定期在文章建议的某个地方进行轮询。