[英]Simplest Way to Schedule Multiple Webjobs from DevOps
I have an app service in Azure running the front end from my MVC5 app, and another app service for web jobs.我在 Azure 中有一个从我的 MVC5 应用程序运行前端的应用程序服务,以及另一个用于 Web 作业的应用程序服务。 The app has several endpoints (GET Actions) which do some processing, send some emails or other simple task.该应用程序有多个端点(GET 操作),它们执行一些处理、发送一些电子邮件或其他简单任务。 Previously when we were hosted on a VPS, we used the Windows Task Scheduler to call each URL on a custom schedule.以前,当我们托管在 VPS 上时,我们使用 Windows 任务计划程序按自定义计划调用每个 URL。 In Azure, the way we're currently doing this is with a Powershell script which uses CURL to fetch the URL and trigger the processing.在 Azure 中,我们目前采用的方法是使用 Powershell 脚本,该脚本使用 CURL 获取 URL 并触发处理。
It seems messy though - as each powershell script has to be uploaded individually, and can't be viewed or changed after uploading.虽然看起来很乱 - 因为每个 powershell 脚本都必须单独上传,并且在上传后无法查看或更改。 I've found various guides on deploying a .NET Core console app, but from what I can tell each job would need it's own project, deployed with it's own pipeline.我找到了有关部署 .NET Core 控制台应用程序的各种指南,但据我所知,每个作业都需要自己的项目,并使用自己的管道进行部署。
Is there a nicer way of doing this, are Webjobs even the right tool for this job, given the seemingly simple task we're performing.考虑到我们正在执行的看似简单的任务,是否有更好的方法来做到这一点,Webjobs 是否甚至是这项工作的正确工具。
As far as I understand your use case, you can use Azure Function App Timer Trigger to accomplish it.据我了解您的用例,您可以使用Azure Function App Timer Trigger来完成它。
A timer trigger lets you run a function on a schedule.计时器触发器可让您按计划运行函数。
The following example shows a C# function that is executed each time the minutes have a value divisible by five (eg if the function starts at 18:57:00
, the next performance will be at 19:00:00
).下面的示例示出了由5每次分钟有一个值整除执行的C#函数(例如,如果在函数开始18:57:00
,接下来的性能将在19:00:00
)。 The TimerInfo
object is passed into the function. TimerInfo
对象被传递到函数中。
[FunctionName("TimerTriggerCSharp")]
public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
{
if (myTimer.IsPastDue)
{
log.LogInformation("Timer is running late!");
}
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
}
The attribute's constructor takes a CRON
expression or a TimeSpan
.该属性的构造函数采用CRON
表达式或TimeSpan
。 You can use TimeSpan
only if the function app is running on an App Service plan.仅当函数应用在应用服务计划上运行时,才能使用TimeSpan
。 TimeSpan
is not supported for Consumption or Elastic Premium Functions
. Consumption or Elastic Premium Functions
不支持TimeSpan
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.