c# - Cron 表达式在 Azure 中不起作用

标签 c# azure cron azure-webjobs

我在 azure 中有一个 Web 作业,我尝试使用 Cron 作业表达式每 2 小时运行一次。我已将作业配置为 OnDemand,并且我相信我已正确设置 Cron 表达式。然而,它永远不会被启动。已经出来2天了。

以下是这项工作的快速概述:

Program.cs

namespace ScheduledTrigger
{
    class Program
    {
        static void Main()
        {
            var config = new JobHostConfiguration();
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }
            var host = new JobHost(config);
            host.Call(typeof(Functions).GetMethod("ManualTrigger"), new { value = 20 });
        }
    }
}

函数.cs

    [NoAutomaticTrigger]
    public static void ManualTrigger()
    {
        var model = new ScheduledTriggerModel();
        ///more stuff here...
    }

webjob-publish-settings.json

{
  "$schema": "http://schemastore.org/schemas/json/webjob-publish-settings.json",
  "webJobName": "ScheduledTrigger",
  "runMode": "OnDemand"
}

设置.作业

{ "schedule": "0 2,4,6,8,10,12,14,16,18,20,22 * * *" }

我也尝试过这个:

设置.作业

{ "schedule": "0 */2 * * *" }

这是我在 Azure 中的工作的屏幕截图。正如您所看到的,我以相同的方式设置了其他作业(使用不同的 Cron 表达式),并且运行得很好。其他作业设置为每天运行,而此作业每天运行多次。

enter image description here

我在这里缺少什么吗? Azure 是否不允许作业每天运行多次(它们现在有内置的调度程序,但价格昂贵)?

最佳答案

我认为你的 cron 表达式不正确。试试这个

"0 0 */2 * * *"

这里是Azure的链接cron 表达式的文档。

希望有帮助。

关于c# - Cron 表达式在 Azure 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51987079/

相关文章:

c# - 如何知道哪些程序集依赖于 system.web.mvc?

c# - 如何在我的 Web API 2 解决方案中发送 "forbidden"响应?

azure - 如何使我的 Windows Azure 应用程序能够抵御 Azure 数据中心灾难性事件?

node.js - setTimeout 未按预期运行?

ruby-on-rails - 从 crontab RedHat 5.8 启动/重新启动 rails 应用程序

php - Slim 3 控制台执行 cron

c# - 如何检测 .Net 中(路由器/网关的)公共(public) IP 地址的变化?

c# - 隐式延迟加载与显式延迟加载

multithreading - 在 Azure Service Fabric actor 内启动线程?

ruby-on-rails - 意外标记附近的语法错误 `('