1

我正在测试持久功能如何扇入/扇出以及如何扩展我的代码。对于这个例子,我模拟了许多短期运行的、CPU 密集型的操作。

并非所有活动似乎都已完成,我不确定为什么或在哪里查找失败日志。

请看下面的代码:

public static class ParallelLoadDurable
    {
        [FunctionName("ParallelLoadDurable")]
        public static async Task<string> RunOrchestrator(
            [OrchestrationTrigger] DurableOrchestrationContext context, ILogger log)
        {
            DateTime StartTimer = DateTime.Now;

            int counter = 0;
            var parallelTasks = new List<Task<string>>();
            var retryOptions = new RetryOptions(
                 firstRetryInterval: TimeSpan.FromSeconds(5),
                 maxNumberOfAttempts: 5);
            for (int i = 0; i < 1000; i++)
            {
                counter += 1;
                DurablePassModel DPM = new DurablePassModel()
                {
                    LoopNum = counter,
                    StartedOn = StartTimer
                };
                Task<string> task = context.CallActivityWithRetryAsync<string>("ParallelLoadDurable_Hello", retryOptions, DPM);
                parallelTasks.Add(task);
            }
            await Task.WhenAll(parallelTasks);

            DateTime CompleteTime = DateTime.Now;
            TimeSpan TS = CompleteTime.Subtract(StartTimer);

            string ret = $"PROCESS COMPLETED: {counter} times for: {TS.TotalMilliseconds} ms.";
            log.LogInformation(ret);
            return ret;
        }

        [FunctionName("ParallelLoadDurable_Hello")]
        public static string SayHello([ActivityTrigger] DurablePassModel val, ILogger log)
        {
            log.LogInformation($"Starting child function num {val.LoopNum.ToString()}.");
            DateTime StartTimer = DateTime.Now;

            var endTime = DateTime.Now.AddSeconds(10);

            while (true)
            {
                if (DateTime.Now >= endTime)
                    break;
            }

            DateTime CompleteTime = DateTime.Now;
            TimeSpan TS = CompleteTime.Subtract(val.StartedOn);
            TimeSpan TSThis = CompleteTime.Subtract(StartTimer);

            string ret = $"Ran this for: {TSThis.TotalSeconds}s - LoopNum: {val.LoopNum} - total time: {TS.TotalSeconds}s.";
            log.LogInformation(ret);

            return ret;
        }

        [FunctionName("ParallelLoadDurable_HttpStart")]
        public static async Task<HttpResponseMessage> HttpStart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequestMessage req,
            [OrchestrationClient]DurableOrchestrationClient starter,
            ILogger log)
        {
            // Function input comes from the request content.
            string instanceId = await starter.StartNewAsync("ParallelLoadDurable", null);

            log.LogInformation($"Started orchestration with ID = '{instanceId}'.");

            return starter.CreateCheckStatusResponse(req, instanceId);
        }
    }

我几乎在每一个案例中都得到了大约 96% 的预期活动完成。这是来自历史表中的结果,其中 EventType = TaskCompleted

同样在“实例”表中,RuntimeStatus 只是保持在“正在运行”

我在哪里可以找到失败列表?

谢谢你的帮助

缺口

4

2 回答 2

1

try catch块包围您的代码,然后使用Ilogger.

可以这样实现

try
{
   //Do something
}
catch(Exception ex){
   log.LogError($"Error in function: {ex.Message}");
}

然后,您可以查看日志中的错误消息,或者Application insights是否有错误消息。

于 2019-05-21T04:25:39.377 回答
1

我建议您为 Azure Functions 配置 Application Insights:https ://docs.microsoft.com/en-us/azure/azure-functions/functions-monitoring 虽然存储数据需要一些成本,但它确实有很大帮助在调查问题时。

此外(或者当您不需要 Application Insights 时)您可以通过C#HTTP查询编排的状态。当您在本地机器上运行和调试时,这也非常有效!

使用 HTTP API,您可以执行以下查询来确定失败的实例:

@functionAppUrl = https://{{appName}}.azurewebsites.net
@code = YOUR_HOST_KEY
@taskHub = YOUR_HUB_NAME (see host.json)
@createdFrom = 2019-02-01T20:00:00Z

GET {{functionAppUrl}}/runtime/webhooks/durabletask/instances
        ?taskHub={{taskHub}}
        &code={{code}}
        &createdTimeFrom={{createdFrom}}
        &runtimeStatus=Failed

我注意到您正在DateTime.Now编排代码中使用。建议使用CurrentUtcDateTime来自 的属性,DurableOrchestrationContext因为编排函数中的行为应该是确定性的。请参阅本节有关编排器代码约束的信息。

于 2019-05-21T10:56:37.780 回答