如何从持久函数协调器获取调用者函数名称?

时间:2020-06-30 15:27:25

标签: azure-functions

我有一个计时器触发器,它使用持久客户端调用协调器。有没有办法从协调器内部获取调用者函数的名称?

[FunctionName("Starter")]
public static async Task Starter(
    [TimerTrigger("0 0 1 * * *", RunOnStartup = true)] TimerInfo myTimer,
    [DurableClient] IDurableClient starter,
    ILogger log)
{
    await starter.StartNewAsync("Orchestrator", null);
}

[FunctionName("Orchestrator")]
public static async Task Orchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    // get caller function name here (Starter, in this example)
}

1 个答案:

答案 0 :(得分:1)

只需将一个参数传递给协调器:

[FunctionName("Starter")]
public static async Task Starter(
    [TimerTrigger("0 0 1 * * *", RunOnStartup = true)] TimerInfo myTimer,
    [DurableClient] IDurableClient starter,
    ILogger log)
{
    await starter.StartNewAsync("Orchestrator", "NAME_OF_THE_CALLER");
}

[FunctionName("Orchestrator")]
public static async Task Orchestrator(
    [OrchestrationTrigger] IDurableOrchestrationContext context)
{
    // get caller function name here (Starter, in this example)
    string caller = context.GetInput<string>();
}