活动函数需要当前时间 - Azure Functions

idu*_*ude 1 c# azure azure-functions azure-durable-functions

所以我有一个持久功能,看起来像这样:

    [FunctionName("functionName")]
    public async Task functionName([OrchestrationTrigger] IDurableOrchestrationContext context)
    {
       // some code here
       string name = "name";
       await context.CallActivityAsync("activityFunction", name);
    }

    [FunctionName("activityFunction")]
    public async Task ActivityFunction([ActivityTrigger] IDurableActivityContext name)
    {
        // perform an operation here
        // need to get current UTC time here
    }
Run Code Online (Sandbox Code Playgroud)

无法从活动上下文中获取当前 UTC 时间。我该如何得到它?

Mar*_*kXA 10

活动函数可以自由使用DateTime.UtcNowDateTimeOffset.UtcNow- 编排器只会运行它一次,然后记住结果以供后续重播。Orchestrator 函数必须使用确定性,IDurableOrchestrationContext.CurrentUtcDateTime因为 Orchestrator 本身内的代码为每次重播返回相同的值非常重要。