调用CallActivityWithRetryAsync()

时间:2019-06-24 20:05:23

标签: azure deadlock azure-durable-functions

我试图在本地使用Visual Studio 2019逐步实现持久功能,但是当我从OrchestrationTrigger调用对context.CallActivityWithRetryAsync(“ MyActivity_Activity”,retryOptions,myActivityParameters)的调用时,该调用始终返回以下内容:

Id = [xxxx],状态= WaitingForActivation,方法=“ {null}”,结果=“ {尚未计算}”

我的第一个猜测是某个地方可能存在死锁,但是我重新启动了机器,仍然看到相同的结果。另外,我尝试在活动的第一行(MyActivity_Activity)设置一个断点,但是没有成功。任何帮助将不胜感激!


使用以下内容:

  • VS 2019 Pro
  • .Net Core 2.2
  • Microsoft.Azure.DurableTask.AzureStorage v1.6.2
  • Microsoft.Azure.WebJobs.Extensions.DurableTask v1.8.2
  • Microsoft.NET.Sdk.Functions v1.0.29

    ...等等。

下面是一些相关的代码片段:

    [FunctionName("MyOrchestrator_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
    [HttpTrigger(AuthorizationLevel.Function, "post")]HttpRequestMessage req,
    [OrchestrationClient]DurableOrchestrationClient starter, ExecutionContext executionContext)
{
    string instanceId = string.Empty;
    MyOrchestratorParameters myOrchestratorParameters = await req.Content.ReadAsAsync<MyOrchestratorParameters>();

    instanceId = await starter.StartNewAsync("MyOrchestrator", myOrchestratorParameters);

    return starter.CreateCheckStatusResponse(req, instanceId);
}



   [FunctionName("MyOrchestrator")]
    public static async Task RunOrchestrator(
        [OrchestrationTrigger] DurableOrchestrationContext context, 
         ExecutionContext executionContext)
    {
        MyOrchestratorParameters myOrchestratorParameters = 
           context.GetInput<MyOrchestratorParameters>();
           ValidateParameters(myOrchestratorParameters);

        var delay = 3000;
        var retry = 3;
        var retryOptions = new 
            RetryOptions(TimeSpan.FromSeconds(delay), retry);        

        MyActivityParameters myActivityParameters = new 
        MyActivityParameters()
        {
            JobNumber = myOrchestratorParameters.JobNumber,
            Stage = myOrchestratorParameters.Stage,
            TemplateId = myOrchestratorParameters.TemplateId
        };
        myActivityResults = 
            context.CallActivityWithRetryAsync<MyActivityResult> 
            ("MyActivity_Activity", retryOptions, myActivityParameters);    

        ...
    }


[FunctionName("MyActivity_Activity")]
public static async Task<MyActivityResult> 
   RunActivity([ActivityTrigger] DurableActivityContext 
   activityContext, ExecutionContext executionContext)
{
    var _myActivityParameters = 
       activityContext.GetInput<MyActivityParameters>();

    //do some stuff & return MyActivityResult object
}   

1 个答案:

答案 0 :(得分:0)

我想我找到了答案。在我对CallActivityWithRetryAsync的调用中,我需要以等待为条件。一旦完成此操作,它便开始工作!