【问题标题】:Call another Azure Function from timer triggered one从计时器触发的调用另一个 Azure 函数
【发布时间】:2020-03-05 19:15:36
【问题描述】:

我想从我的计时器触发的天蓝色函数中调用另一个(不是计时器触发的)天蓝色函数。 它可以编译,但在运行时出现错误:

System.ArgumentException: 'The function 'HelloWorld' doesn't exist, is disabled, or is not an orchestrator function. Additional info: No orchestrator functions are currently registered!'

我将它简化为这个小代码 sn-p。

    [FunctionName("HelloWorld")]
    public static string HelloWorld([ActivityTrigger] string name, ILogger log)
    {
        return $"Hello {name}!";
    }

    [FunctionName("DownloadLiveList")]
    public async void DownloadLiveList([DurableClient] IDurableOrchestrationClient client, [TimerTrigger("0 0 0 * * *", RunOnStartup = true)]TimerInfo myTimer, ILogger log)
    {
        await client.StartNewAsync<string>("HelloWorld", "Magdeburg");
    }

当我从微软官方示例中获得这种天蓝色函数级联的想法时,我不知道为什么函数“HelloWorld”没有注册。上传到 azure 后,该函数在 azure 门户中与该类中的所有其他函数一样可见。

【问题讨论】:

    标签: azure azure-functions azure-functions-core-tools timer-trigger


    【解决方案1】:

    您的时间触发函数需要调用使用 Durable Function Framework 编写的启动函数。这是一个示例:

    [FunctionName("Function1")]
    public async Task Run([TimerTrigger("0 */1 * * * *")]TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
    
        var url = "http://localhost:7071/api/Durable_Starter";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.AutomaticDecompression = DecompressionMethods.GZip;
    
        using (HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync())
        using (Stream stream = response.GetResponseStream())
        using (StreamReader reader = new StreamReader(stream))
        {
            var html = reader.ReadToEnd();
            log.LogInformation(html);
        }
    }
    
    [FunctionName("Durable_Starter")]
    public async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")]HttpRequest req, [DurableClient] IDurableClient starter, ILogger log)
    {
        log.LogInformation("C# HTTP trigger function processed a request.");
    
        string instanceId = await starter.StartNewAsync("Durable_Orchestrator");
    
        log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
    
        var checkStatusResponse = starter.CreateCheckStatusResponse(req, instanceId);
    
        return checkStatusResponse;
    }
    
    
    [FunctionName("Durable_Orchestrator")]
    public async Task RunOrchestrator([OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log)
    {
        var message = await context.CallActivityAsync<string>("HelloWorld", "Thiago");
        log.LogInformation(message);
    }
    
    [FunctionName("HelloWorld")]
    public string HelloWorldActivity([ActivityTrigger] string name)
    {
        return $"Hello {name}!";
    }
    

    【讨论】:

    • 谢谢。但是不需要 Http-Stuff,是吗? Durable_Starter 可以启动定时器触发,调用 Durable_Orchestrator 调用 HelloWorld。
    • 我知道你想要相反的结果。时间触发器调用 Durable Orchestrator
    猜你喜欢
    • 2021-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    相关资源
    最近更新 更多