skip to Main Content

Little bit new to azure durable function. I am trying out fanout/fanin Concept within the azure function.

    [FunctionName("MasterListUpdate")]
    public async Task<List<Task<string>>> RunOrchestrator(
   [OrchestrationTrigger] IDurableOrchestrationContext context)
    {
        var outputs = new List<Task<string>>();
              
        var datalist = context.GetInput<List<string>>();
      
        foreach (var state in StateList.States)
        {            
          
            outputs.Add(context.CallActivityAsync<string>("UpdatingTheDataSet", state));
        }          
        await Task.WhenAll(outputs.ToArray());         
        return outputs.ToList();
    }

    [FunctionName("UpdatingTheDataSet")]
    public async Task<string> AddData([ActivityTrigger]string state,ILogger log)
    {
               
       await _insertingAllData.UpdatingReleventData(state, log);       
        return state;           
    }


    [FunctionName("DurableFunctionStart")]
    public async Task HttpStart(
         [TimerTrigger("0 */60 * * * *"
        #if DEBUG
                    ,RunOnStartup =true
        #endif
        )]
    TimerInfo myTimer,

        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("MasterListUpdate", StateList.States);
        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");           
    }      

try to trigger a timer function Using azure durable function.Locally this work fine. When try to host in azure portal

enter image description here

it throw a error like this. Could not able to find out where I am doing wrong here.

** Note:- StateList.States this is a static list.
Locally this work fine**

2

Answers


  1. We tried to reproduced the same scenario and its working fine.

    Here you are facing the issue and it may be cause for the error.

    await _insertingAllData.UpdatingReleventData(state, log); 
    

    So, rewriting this code as below example and it’s working as expected.

    Example Code :-

    using System.Collections.Generic;
    using System.Linq;
    using System.Net.Http;
    using System.Threading.Tasks;
    using Microsoft.Azure.WebJobs;
    using Microsoft.Azure.WebJobs.Extensions.DurableTask;
    using Microsoft.Azure.WebJobs.Extensions.Http;
    using Microsoft.Azure.WebJobs.Host;
    using Microsoft.Extensions.Logging;
    
    namespace DuralbeFunction
    {
        public static class Function1
        {
            [FunctionName("RunOrchestrator")]
            public static async Task<List<Task<string>>> RunOrchestrator(
                [OrchestrationTrigger] IDurableOrchestrationContext context)
            {
                var stateList = new List<StateList>()
                {
                    new StateList(){State="Delhi"},
                    new StateList(){State="UP"},
                    new StateList(){State="Goa"},
                };
     
                var outputs = new List<Task<string>>();
                var datalist = context.GetInput<List<string>>();
                foreach (var state in stateList)
                {
                    outputs.Add(context.CallActivityAsync<string>("Activity_Function1_Hello", state.State));
                }
                await Task.WhenAll(outputs.ToArray());
                return outputs.ToList();
            }
            
            [FunctionName("Activity_Function1_Hello")]
            public static string SayHello([ActivityTrigger] string name, ILogger log)
            {
                log.LogInformation($"Saying hello to {name}.");
                return $"Hello {name}!";
            }
    
            [FunctionName("Function1_HttpStart")]
            public static async Task<HttpResponseMessage> HttpStart(
                [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
                [DurableClient] IDurableOrchestrationClient starter,
                ILogger log)
            {
                string instanceId = await starter.StartNewAsync("RunOrchestrator", null);
                log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
                return starter.CreateCheckStatusResponse(req, instanceId);
            }    
        }
        public class StateList
        {
            public string State { get; set; }
        }
    }
    

    Output : –

    enter image description here

    Kudo output :-
    enter image description here

    Login or Signup to reply.
  2. I was getting the same cryptic error message along with a FunctionInvocationException (related to the Orchestrator) when trying to invoke the Orchestrator function from the Azure portal (in my case, I as testing it through the Code + Test section).

    After lots of researching, I found out invoking the Orchestrator through the Azure portal is not allowed. Invoking it through a tool like Postman worked without any issues. I hope this saves others some time.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search