计划的Web作业使计划混乱

时间:2017-09-28 12:15:45

标签: azure azure-webjobs azure-webjobssdk

我的网络工作需要每天凌晨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中配置了我的网络作业。

我在这里缺少什么?

3 个答案:

答案 0 :(得分:2)

您需要将您的逻辑放在Program.cs中。

运行时将通过执行可执行文件运行WebJob,在Program.cs中运行Main方法。

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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