gpt4 book ai didi

本地运行时,Azure 持久函数在启动时多次运行

转载 作者:行者123 更新时间:2023-12-03 07:00:08 24 4
gpt4 key购买 nike

我有一个http触发的azure持久函数,带有一个名为“ExecuteWork”的编排触发器和两个事件,即“HandleClaimsForms”和“HandleApplicationForms”。我将在下面添加它们的定义。该函数用于处理 blob 存储容器中的 PDF。当本地运行时,它将在启动时执行四到五次“HandleClaimsForms”,而不会被调用。

以下是它生成的日志:

Functions:

Function1: [GET,POST] http://localhost:7071/api/Function1

ExecuteWork: orchestrationTrigger

HandleApplicationForms: activityTrigger

HandleClaimsForms: activityTrigger

[2022-06-07T12:39:44.587Z] Executing 'HandleClaimsForms' (Reason='(null)', Id=c45878fe-35c8-4a57-948e-0b43da969427)
[2022-06-07T12:39:44.587Z] Executing 'HandleClaimsForms' (Reason='(null)', Id=0fb9644d-6748-4791-96cf-a92f6c161a97)
[2022-06-07T12:39:44.587Z] Executing 'HandleClaimsForms' (Reason='(null)', Id=9a39a169-a91d-4524-b5e5-63e6226f70ec)
[2022-06-07T12:39:44.587Z] Executing 'HandleClaimsForms' (Reason='(null)', Id=b3697f6b-7c96-4497-826f-3894359ff361)
[2022-06-07T12:39:44.587Z] Executing 'HandleClaimsForms' (Reason='(null)', Id=3ca3bbce-1657-453b-a5b3-e9dbdb940302)

以下是函数定义:

函数入口点

[FunctionName("Function1")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
string instanceID = await starter.StartNewAsync("ExecuteWork");

return starter.CreateCheckStatusResponse(req, instanceID);
}

编排触发器

[FunctionName("ExecuteWork")]
public async Task<bool> ProcessForms(
[OrchestrationTrigger] IDurableOrchestrationContext context,
ILogger log)
{
bool success = true;
try
{
await context.CallActivityAsync("HandleClaimsForms", success);
await context.CallActivityAsync("HandleApplicationForms", success);

return success;
}
catch (Exception err)
{
log.LogInformation($"The following error was thrown: {err}");
success = false;
return success;
}
}

HandleClaimsForm 事件

        public async Task<bool> ProcessClaimsForms(
[ActivityTrigger]bool success)
{

await _docHandler.Handle();

return success;
}

HandleApplicationForm 事件

[FunctionName("HandleApplicationForms")]
public async Task<bool> ProcessApplicationForms(
[ActivityTrigger]bool success)
{

await _appHandler.HandleJsonApplicationFormAsync();

return success;
}

最佳答案

您可以采用的解决方法之一来解决上述问题,

基于MICROSOFT DOCUMENT关于可靠性的是:

  • Durable Functions uses event sourcing transparently. Behind the scenes, the await (C#) or yield (JavaScript/Python) operator in anorchestrator function yields control of the orchestrator thread backto the Durable Task Framework dispatcher.

  • The orchestrator wakes up and re-executes the entire function from scratch to rebuild the local state whenever an orchestration functionis given more work to do (for instance, when a response message isreceived or a durable timer expires). The Durable Task Frameworkanalyses the orchestration's execution history if the code tries toinvoke a function or do any other async task during the replay. In theevent that it discovers that the activity function has already run andproduced a result, it replays that result while the orchestrator codekeeps running. Playback continues until the function code terminatesor until additional async work has been scheduled.

另一种方法是使用 dependency injection .

有关更多信息,请参阅以下链接:-

关于本地运行时,Azure 持久函数在启动时多次运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72531493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com