Azure WebJobs TimerTrigger 未触发
Azure WebJobs TimerTrigger not triggering
我正在尝试 运行 WebJob 作为控制台应用程序,当我添加 RunOnStartup = true
时它可以工作,但我需要它只与 TimerTrigger 一起工作。
这是我的代码
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
public static void TimerJob([TimerTrigger("0 0 8 * * *")] TimerInfo timerInfo)
{
Console.WriteLine("Job Work");
}
我需要什么才能使此代码正常工作?
首先,按照 here in the Local Development section 所述添加 JobHostConfiguration Tracing。否则您将看不到控制台文本。如果你在本地 运行,你也可以随时设置断点。
另请记住,TimerTrigger 在 Azure 上使用 Web 应用程序时区,在本地使用 运行 时使用计算机时区。要定义 Web App 时区,请遵循 these steps.
此行为是由于 TimerTrigger
中的一个问题,已在 v1.0.1 版本中修复现在在 Nuget 上直播。
问题是我们在安排事件时在内部使用 UTC 时间,而不是您期望的 当地时间。虽然这可能会在本地 运行ning 时造成混乱,但您的工作仍会 运行 在 Azure 中按计划正确进行。
不过,这个问题现在已经解决了。
这可能不是您的特定问题的答案,但它回答了完全相同的问题。我注意到它不会在程序 class 中找到 TimerTrigger 函数。当 运行 我刚得到
Development settings applied
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.).
Job host started
将它们放入函数 class 后触发得很好。
我正在尝试 运行 WebJob 作为控制台应用程序,当我添加 RunOnStartup = true
时它可以工作,但我需要它只与 TimerTrigger 一起工作。
这是我的代码
public static void Main()
{
JobHostConfiguration config = new JobHostConfiguration();
config.UseTimers();
JobHost host = new JobHost(config);
host.RunAndBlock();
}
public static void TimerJob([TimerTrigger("0 0 8 * * *")] TimerInfo timerInfo)
{
Console.WriteLine("Job Work");
}
我需要什么才能使此代码正常工作?
首先,按照 here in the Local Development section 所述添加 JobHostConfiguration Tracing。否则您将看不到控制台文本。如果你在本地 运行,你也可以随时设置断点。
另请记住,TimerTrigger 在 Azure 上使用 Web 应用程序时区,在本地使用 运行 时使用计算机时区。要定义 Web App 时区,请遵循 these steps.
此行为是由于 TimerTrigger
中的一个问题,已在 v1.0.1 版本中修复现在在 Nuget 上直播。
问题是我们在安排事件时在内部使用 UTC 时间,而不是您期望的 当地时间。虽然这可能会在本地 运行ning 时造成混乱,但您的工作仍会 运行 在 Azure 中按计划正确进行。
不过,这个问题现在已经解决了。
这可能不是您的特定问题的答案,但它回答了完全相同的问题。我注意到它不会在程序 class 中找到 TimerTrigger 函数。当 运行 我刚得到
Development settings applied
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.).
Job host started
将它们放入函数 class 后触发得很好。