简体   繁体   English

.Net Quartz Windows Service解决作业依赖性

[英].Net Quartz Windows Service resolve job dependencies

I've just started using Quartz.Net - basically I want to run it as a Windows Service and schedule jobs that are in different assemblies using the IJob interface. 我刚刚开始使用Quartz.Net-基本上我想将其作为Windows服务运行,并使用IJob界面计划在不同程序集中的作业。 To do this by default I need to put the assemblies containing the Jobs (and all their dependencies) in the root folder with the Quartz.exe. 默认情况下,要执行此操作,我需要将包含Jobs(及其所有依赖项)的程序集与Quartz.exe放在根文件夹中。 All good - I've got this working. 一切都很好-我已经做好了。 However I'd like to put the different jobs from different assemblies into specific folders under the root directory. 但是,我想将来自不同程序集的不同作业放入根目录下的特定文件夹中。 When I do this Quartz cant resolve the dependencies - I realise I can create my own assembly resolver however I have no idea where to put it or what should instantiate it - any help would be great. 当我这样做时,Quartz无法解析依赖关系-我意识到我可以创建自己的程序集解析器,但是我不知道将其放置在何处或应实例化它-任何帮助都将非常有用。

I tried creating my own JobFactory and resolving the dependecies in there based on a supplied path. 我尝试创建自己的JobFactory并根据提供的路径在其中解决依赖项。 However it dosnt work - for some reason the JobFactory fails because it cant find the Job dependecies - which is puzzling because the Job is only created in the JobFactory.NewJob method as below: 但是,它不起作用-由于某种原因JobFactory失败,因为它找不到Job依赖关系-这令人困惑,因为Job仅在JobFactory.NewJob方法中创建,如下所示:

  public class MyQuartzJobFactory : IJobFactory

{ //Does this line then fails because it cant find dependency private static readonly ILog log = LogManager.GetLogger(typeof(MyQuartzJobFactory)); {//此行然后失败,因为它找不到依赖项私有静态只读ILog log = LogManager.GetLogger(typeof(MyQuartzJobFactory));

public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
{
  IJobDetail jobDetail = bundle.JobDetail;
  Type jobType = jobDetail.JobType;
  try
  {
    if (log.IsDebugEnabled)
    {
      log.Debug(string.Format(CultureInfo.InvariantCulture, "Producing instance of Job '{0}', class={1}", jobDetail.Key, jobType.FullName));
    }

    string path = "";
    if (jobDetail.JobDataMap.ContainsKey("custPath"))
    {
      path = jobDetail.JobDataMap["custPath"].ToString();
    }

    return ObjectUtils.InstantiateType<IJob>(jobType);
  }
  catch (Exception e)
  {
    SchedulerException se = new SchedulerException(string.Format(CultureInfo.InvariantCulture, "Problem instantiating class '{0}'", jobDetail.JobType.FullName), e);
    throw se;
  }
}

/// <summary>
/// Allows the job factory to destroy/cleanup the job if needed. 
/// No-op when using SimpleJobFactory.
/// </summary>
public void ReturnJob(IJob job)
{
  var disposable = job as IDisposable;
  if (disposable != null)
  {
    disposable.Dispose();
  }
}

} }

If you have the assemblies in folders under where the executable is, it might be easier to use the probing element in the configuration file. 如果程序集位于可执行文件所在的文件夹中,则使用配置文件中的探测元素可能会更容易。 Or, take a look at how the server example installs the service and create your own service that sets your assembly dependencies in it. 或者,看看服务器示例如何安装服务并创建自己的服务来在其中设置程序集依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM