gpt4 book ai didi

Azure 函数,延迟

转载 作者:行者123 更新时间:2023-12-03 04:56:57 30 4
gpt4 key购买 nike

我有一个 CRM 系统,当添加联系人时,我想将他们添加到会计系统中。

我在 CRM 系统中设置了一个 Webhook,将联系人传递给 Azure 函数。 Azure 函数连接到会计系统 API 并在那里创建它们。

在将用户添加到会计系统之前,我需要做一些其他处理。

收到 Webhook 后,我需要大约 5 分钟的延迟才能将用户添加到会计系统。

我不想在 Azure 函数中添加暂停或延迟语句,因为有超时限制,而且它是一个消耗计划,所以我希望每个函数都能快速执行。

我正在使用 Powershell 核心。

服务总线队列是实现此目的的最佳方法吗?

最佳答案

您可以使用 Timer in a Durable Function为了这。那么你就不需要像队列这样的额外组件。一个Durable Function是你所需要的全部。例如(警告:未编译此):

注意:耐用功能do support powershell但我不;-) 所以下面的代码是为了理解这个概念。

[FunctionName("Orchestration_HttpStart")]
public static async Task<HttpResponseMessage> HttpStart(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
[DurableClient] IDurableOrchestrationClient starter,
ILogger log)
{
// Function input comes from the request content.
string content = await req.Content.ReadAsStringAsync();
string instanceId = await starter.StartNewAsync("Orchestration", content);

log.LogInformation($"Started orchestration with ID = '{instanceId}'.");
return starter.CreateCheckStatusResponse(req, instanceId);
}

[FunctionName("Orchestration")]
public static async Task Run(
[OrchestrationTrigger] IDurableOrchestrationContext context)
{
var requestContent = context.GetInput<string>();

DateTime waitAWhile = context.CurrentUtcDateTime.Add(TimeSpan.FromMinutes(5));
await context.CreateTimer(waitAWhile, CancellationToken.None);
await context.CallActivityAsync("ProcessEvent", requestContent);
}

[FunctionName("ProcessEvent")]
public static string ProcessEvent([ActivityTrigger] string requestContent, ILogger log)
{
// Do something here with requestContent

return "Done!";
}

I would rather not add a pause or delay statement in the Azure Function as there is a timeout limit, and also It's a consumption plan so I want each function to action quickly.

计时器引入的 5 分钟延迟不会计入事件时间,因此您不会用完这些分钟的消耗计划时间。

关于Azure 函数,延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66457509/

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