Quartz.NET 如果作业实例化失败则不会抛出异常
Quartz.NET doesn't throw exception if job instantiation fails
我正在通过 castle windsor 使用 Quartz.NET,一切正常,但其中一项工作使用了身份依赖项,如果我没有注册依赖项,它不会抛出异常。
注册码
static void RegisterTriggerListeners(IWindsorContainer container)
{
container.Register(DefaultInterfaces());
container.Register(Connections());
container.Register(
Component.For<Quartz.IScheduler>().Instance(StdSchedulerFactory.GetDefaultScheduler()),
Component.For<IJobFactory>().ImplementedBy<WindsorJobFactory>().DependsOn(Dependency.OnValue<IWindsorContainer>(container)).LifestyleTransient(),
// See: http://blog.nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime/
// public void Install(IWindsorContainer container, IConfigurationStore store) section near the end of the page
Classes.FromThisAssembly().BasedOn<IHttpController>().LifestyleScoped()
//,
//Component
// .For<IIdentity>()
// .UsingFactoryMethod(WindowsIdentity.GetCurrent)
// .LifestyleSingleton()
);
RegisterJobs(container);
}
使用身份的工作
class ValidationStep : Step<ITransactionLineValidationStep, TransactionLine>, ITransactionLineValidationStep
{
private IImpersonatedWebClient ImpersonatedWebClient { get; }
private ISettings Settings { get; }
readonly IIdentity _identity;
private string ValidationAddress { get; set; }
private const string ValidationResultError = "Error";
public ValidationStep(IImpersonatedWebClient impersonatedWebClient,
ISettings settings,
IIdentity identity)
{
ImpersonatedWebClient = impersonatedWebClient;
Settings = settings;
_identity = identity;
}
如果我注释掉身份注册 - 调度程序 运行 正常但停止 运行 使用作业而不抛出异常。
如果依赖项未注册,有什么方法可以让我收到通知或抛出异常?
这可能不是 Castle 问题,因为在组件解析期间缺少某些非可选(构造函数)依赖项时,Castle 总是抛出异常。
您看到的是 Quartz.NET 设计的结果 - 如果在作业创建期间抛出异常(使用作业工厂方法 NewJob
),Quartz 会捕获它并将其转换为 SchedulerException
(参见 JobRunShell line 94) which is later swalowed (see QuartzSchedulerThread line 420)。同时,Quartz 调用附加到其调度器
的任何 ISchedulerListener
的 SchedulerError
方法
所有这一切的原因是为了保护 Quartz 调度程序线程不破坏应用程序。
如果你只想在开发过程中检查这个,只需配置 Quartz 日志记录(使用 Common.Logging 框架 - 请参阅 documentation - at the bottom) and you'll see errors like this in log. Otherwise you can write your own ISchedulerListener
来处理 SchedulerError
"event" 并做任何你想要那里...
注意:提供的源代码链接来自 master 分支,它是 Quartz.NET 尚未发布的 3.x 版本,但 2.x 版本工作相同...
我正在通过 castle windsor 使用 Quartz.NET,一切正常,但其中一项工作使用了身份依赖项,如果我没有注册依赖项,它不会抛出异常。
注册码
static void RegisterTriggerListeners(IWindsorContainer container)
{
container.Register(DefaultInterfaces());
container.Register(Connections());
container.Register(
Component.For<Quartz.IScheduler>().Instance(StdSchedulerFactory.GetDefaultScheduler()),
Component.For<IJobFactory>().ImplementedBy<WindsorJobFactory>().DependsOn(Dependency.OnValue<IWindsorContainer>(container)).LifestyleTransient(),
// See: http://blog.nikosbaxevanis.com/2012/07/16/using-the-web-api-dependency-resolver-with-castle-windsor-scoped-lifetime/
// public void Install(IWindsorContainer container, IConfigurationStore store) section near the end of the page
Classes.FromThisAssembly().BasedOn<IHttpController>().LifestyleScoped()
//,
//Component
// .For<IIdentity>()
// .UsingFactoryMethod(WindowsIdentity.GetCurrent)
// .LifestyleSingleton()
);
RegisterJobs(container);
}
使用身份的工作
class ValidationStep : Step<ITransactionLineValidationStep, TransactionLine>, ITransactionLineValidationStep
{
private IImpersonatedWebClient ImpersonatedWebClient { get; }
private ISettings Settings { get; }
readonly IIdentity _identity;
private string ValidationAddress { get; set; }
private const string ValidationResultError = "Error";
public ValidationStep(IImpersonatedWebClient impersonatedWebClient,
ISettings settings,
IIdentity identity)
{
ImpersonatedWebClient = impersonatedWebClient;
Settings = settings;
_identity = identity;
}
如果我注释掉身份注册 - 调度程序 运行 正常但停止 运行 使用作业而不抛出异常。 如果依赖项未注册,有什么方法可以让我收到通知或抛出异常?
这可能不是 Castle 问题,因为在组件解析期间缺少某些非可选(构造函数)依赖项时,Castle 总是抛出异常。
您看到的是 Quartz.NET 设计的结果 - 如果在作业创建期间抛出异常(使用作业工厂方法 NewJob
),Quartz 会捕获它并将其转换为 SchedulerException
(参见 JobRunShell line 94) which is later swalowed (see QuartzSchedulerThread line 420)。同时,Quartz 调用附加到其调度器
ISchedulerListener
的 SchedulerError
方法
所有这一切的原因是为了保护 Quartz 调度程序线程不破坏应用程序。
如果你只想在开发过程中检查这个,只需配置 Quartz 日志记录(使用 Common.Logging 框架 - 请参阅 documentation - at the bottom) and you'll see errors like this in log. Otherwise you can write your own ISchedulerListener
来处理 SchedulerError
"event" 并做任何你想要那里...
注意:提供的源代码链接来自 master 分支,它是 Quartz.NET 尚未发布的 3.x 版本,但 2.x 版本工作相同...