我已经将控制台应用程序发布为连续运行的 Web 作业,并使用 Quartz 来管理调度。
当我在本地运行该文件时,Quartz 工作正常。
当我将文件作为 Web 作业运行时,我可以看到它按计划运行,并且执行了预期的操作。
但是,当我查看网络作业日志时,我看到如下错误:
[07/06/2017 09:48:59 > dd118a: ERR ] Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Quartz, Version=2.5.0.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4' or one of its dependencies. The system cannot find the file specified.
我在这里看到了其他类似的问题,但这通常涉及人们在本地计算机上遇到程序集不匹配问题。
如何检查此错误是否严重,以及如何修复它?
建议?
最佳答案
我使用 Quartz.NET 库 (v2.5.0) 使用以下示例代码进行了测试,它在本地和部署为 WebJobs 上都运行良好。
using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace QuartzTest
{
class Program
{
static void Main(string[] args)
{
try
{
Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter { Level = Common.Logging.LogLevel.Info };
// Grab the Scheduler instance from the Factory
IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
// and start it off
scheduler.Start();
// define the job and tie it to our HelloJob class
IJobDetail job = JobBuilder.Create<HelloJob>()
.WithIdentity("job1", "group1")
.Build();
// Trigger the job to run now, and then repeat every 10 seconds
ITrigger trigger = TriggerBuilder.Create()
.WithIdentity("trigger1", "group1")
.StartNow()
.WithSimpleSchedule(x => x
.WithIntervalInSeconds(10)
.RepeatForever())
.Build();
// Tell quartz to schedule the job using our trigger
scheduler.ScheduleJob(job, trigger);
// some sleep to show what's happening
Thread.Sleep(TimeSpan.FromSeconds(60));
// and last shut down the scheduler when you are ready to close your program
scheduler.Shutdown();
}
catch (SchedulerException se)
{
Console.WriteLine(se);
}
//Console.WriteLine("Press any key to close the application");
//Console.ReadKey();
}
public class HelloJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Console.WriteLine("Greetings from HelloJob!");
}
}
}
}
包.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Common.Logging" version="3.3.1" targetFramework="net452" />
<package id="Common.Logging.Core" version="3.3.1" targetFramework="net452" />
<package id="Microsoft.Web.WebJobs.Publish" version="1.0.12" targetFramework="net452" />
<package id="Quartz" version="2.5.0" targetFramework="net452" />
</packages>
WebJobs 日志
Could not load file or assembly 'Quartz, Version=2.5.0.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4' or one of its dependencies. The system cannot find the file specified.
请使用the Kudu Console访问站点的文件夹并确保 Quartz 及其依赖项文件在那里 (D:\home\site\wwwroot\app_data\jobs\continuous{jobname})。您可以尝试删除作业并将其重新部署到 Azure Web 应用程序。
此外,Azure WebJob itself can be triggered on a schedule ,如果可能的话,你可以使用它。
关于Quartz 失败的 Azure Web 作业,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946593/