1

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. 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. 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.

I tried creating my own JobFactory and resolving the dependecies in there based on a supplied path. 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:

  public class MyQuartzJobFactory : IJobFactory

{ //Does this line then fails because it cant find dependency private static readonly 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();
  }
}

}

gisWeeper
  • 501
  • 6
  • 18
  • 2
    I think you need to define your own `JobFactory`, http://stackoverflow.com/questions/20587433/whats-the-purpose-of-returnjob-in-ijobfactory-interface-for-quartz-net – Maxim Zhukov Aug 20 '15 at 15:40
  • No I tried this and it dosnt work - for some reason he JobFactory fails because it cant find the Job dependecies - which is puzzling because the Job is only created in the JobFactory.NewJob method. – gisWeeper Oct 15 '15 at 16:16

1 Answers1

1

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.

jvilalta
  • 6,679
  • 1
  • 28
  • 36
  • I am creating my own server like in the server example you reference - I'm just not sure where I should resolve the dependencies for the configured (using the quartz_jobs.xml configuration) Jobs that are loaded. The probing element looks interesting - however its possible that different jobs in different assemblies might use different versions of the same dependency. – gisWeeper Aug 21 '15 at 08:24