以编程方式计划一次执行Azure功能 [英] Programmatically Schedule one-time execution of Azure function

查看:57
本文介绍了以编程方式计划一次执行Azure功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经浏览过Azure中的WebJob,Functions和Logic Apps的文档,但是我找不到通过代码安排一次执行流程的方法.我的用户需要能够安排将通知安排在将来的特定时间(通常在计划后的几个小时或一天之内)发送出去.我在这些进程上阅读的所有内容都使用了CRON表达式,该表达式不是为一次性执行而设计的.我意识到我可以安排作业按间隔运行,并检查数据库以查看是否需要运行其余的作业,但是我想避免在可能的情况下不必要地运行作业.感谢您的帮助.

I have looked through documentation for WebJobs, Functions and Logic Apps in Azure but I cannot find a way to schedule a one-time execution of a process through code. My users need to be able to schedule notifications to go out at a specific time in the future (usually within a few hours or a day from being scheduled). Everything I am reading on those processes is using CRON expressions which is not designed for one-time executions. I realize that I could schedule the job to run on intervals and check the database to see if the rest of the job needs to run, but I would like to avoid running the jobs unnecessarily if possible. Any help is appreciated.

如果相关,那么我正在使用C#,ASP.NET MVC Core,App Services和SQL数据库,它们都托管在Azure中.我的计划是使用Logic应用程序检查数据库中的计划事件,并通过Twilio,SendGrid和iOS/Android推送通知发送通知.

If it is relevant, I am using C#, ASP.NET MVC Core, App Services and a SQL database all hosted in Azure. My plan was to use Logic apps to check the database for a scheduled event and send notifications through Twilio, SendGrid, and iOS/Android push notifications.

推荐答案

您可以使用具有递延可见性的Azure队列触发器.这将使消息在指定的超时时间内不可见.方便地用作计时器.

You could use Azure Queue trigger with deferred visibility. This will keep the message invisible for a specified timeout. This conveniently acts as a timer.

CloudQueue queueOutput; // same queue as trigger listens on 
var strjson = JsonConvert.SerializeObject(message); // message is your payload
var cloudMsg = new CloudQueueMessage(strjson);

var delay = TimeSpan.FromHours(1); 
queueOutput.AddMessage(cloudMsg, initialVisibilityDelay: delay);

请参见

See https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.storage.queue.cloudqueue.addmessage?view=azure-dotnet for more details on this overload of AddMessage.

这篇关于以编程方式计划一次执行Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆