Вызовите другую Azure функцию из сработавшего таймера - PullRequest
0 голосов
/ 05 марта 2020

Я хочу вызвать другую (не сработавшую по таймеру) azure функцию из моей сработавшей по таймеру функции azure. Он компилируется, но во время выполнения я получаю сообщение об ошибке:

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

Я уменьшил его до этого крошечного фрагмента кода.

    [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");
    }

Поскольку я взял идею из официального примера Microsoft для такого рода azure каскадная функция, я понятия не имею, почему функция "HelloWorld" не зарегистрирована. После загрузки в azure функция видна на портале azure, как и все другие функции из класса.

1 Ответ

1 голос
/ 05 марта 2020

Ваша функция запуска по времени должна вызывать функцию запуска, написанную с помощью 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}!";
}
...