azure - Azure 函数,延迟
问题描述
我有一个 CRM 系统,当添加联系人时,我想将他们添加到会计系统中。
我在 CRM 系统中设置了一个 webhook,将联系人传递给 Azure 函数。Azure 函数连接到会计系统 API 并在那里创建它们。
在将用户添加到会计系统之前,我还需要做一些其他处理。
在收到 webhook 后,我需要大约 5 分钟的延迟才能将用户添加到会计系统。
我宁愿不在 Azure 函数中添加暂停或延迟语句,因为有超时限制,而且它是一个消耗计划,所以我希望每个函数都能快速行动。
我正在使用 Powershell 内核。
服务总线队列是做到这一点的最佳方式吗?
解决方案
为此,您可以在 Durable Function中使用Timer 。然后你就不需要像队列这样的额外组件了。耐用的功能就是您所需要的。例如(警告:未编译此):
注意:Durable Functions确实支持 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!";
}
我宁愿不在 Azure 函数中添加暂停或延迟语句,因为有超时限制,而且它是一个消耗计划,所以我希望每个函数都能快速行动。
计时器引入的 5 分钟延迟不会算作活动时间,因此您不会用完这些分钟的消费计划时间。
推荐阅读
- php - 需要时间窗口检查器功能
- macos - 我可以截取一个艰难的 shh 连接并在其他 Mac 上打开它吗?
- flutter - 如何删除 Flutter 按钮栏中的多余空格?
- sql - 我们怎样才能使这个查询更有效率?
- python - 如何在没有任何训练过程的情况下使用保存的权重进行下次预测?
- python - 代码的语法错误:“def 函数”等级字母上的语法无效
- javascript - 为什么我在 saga 中的 getRequest() 在 postRequest 之后看不到来自 json.db 的数据
- python - Python转义re.split将反斜杠+符号视为另一个符号
- python - Pandas 创建列的列表,其行值包含“和”分隔符
- python - 从超参数调整作业创建用于管道的模型