【问题标题】:Scheduled web job confusing about schedule计划的网络作业对计划感到困惑
【发布时间】:2017-09-28 12:15:44
【问题描述】:

我有一个需要在每天凌晨 1 点运行的网络作业。 我的 settings.job 是这样配置的:

{
    "schedule": "0 0 1 * * *",
    "is_singleton":  true 
}

我在 Functions.cs 中声明了函数

   namespace Dsc.Dmp.SddUpgrade.WebJob
{
    using System;
    using System.IO;

    using Microsoft.Azure.WebJobs;

    public class Functions
    {
        public static void TriggerProcess(TextWriter log)
        {
            log.Write($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

我收到以下日志:

[09/28/2017 12:02:05 > 9957a4: SYS INFO] Status changed to Running
[09/28/2017 12:02:07 > 9957a4: INFO] No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

当我阅读文档时,有些人正在使用这样的函数签名:

public static void TriggerProcess([TimerTrigger("0 0 1 * * *")] TimerInfo timerInfo, TextWriter log)

但是,这对我来说似乎不合逻辑,因为已经在 settings.job 中安排了我的网络作业。

我在这里错过了什么?

【问题讨论】:

  • 我们可以看看你的 Program.cs 的 Main 函数吗?

标签: azure azure-webjobs azure-webjobssdk


【解决方案1】:

如果您使用 settings.job 文件来安排您的 WebJob,您的逻辑应该放在 Program.cs 的 Main 函数中。如果你走这条路,你可以忽略 Functions.cs 文件。这对于将控制台应用程序迁移到 WebJob 并安排它非常有用。

TimerTrigger 是一个 WebJob 扩展。它很有用,因为在 Functions.cs 中可以有多个方法,每个方法都有一个单独的 TimerTrigger,它按不同的计划执行。要使用这些,您的 WebJob 需要是连续的。

【讨论】:

【解决方案2】:

你需要把你的逻辑放在 Program.cs 中。

运行时将通过执行可执行文件、运行 Program.cs 中的 Main 方法来运行您的 WebJob。

【讨论】:

    【解决方案3】:

    您似乎在函数定义中缺少 [FunctionName("TriggerProcess")] 属性,这就是您收到“找不到作业”错误的原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-19
      • 2013-12-14
      • 1970-01-01
      相关资源
      最近更新 更多