I have the Quartz Job shown below
public class ExtractTradesJob: IJob
{
private ITradeExtractor _tradeExtractor;
public ExtractTradesJob(ITradeExtractor tradeExtractor)
{
_tradeExtractor = tradeExtractor;
}
public async Task GetTradesAsync(DateTime dateTime)
{
Console.WriteLine(dateTime);
}
void IJob.Execute(IJobExecutionContext context)
{
Task.Run(async () => await GetTradesAsync(DateTime.Now));
}
}
I have 2 issues
- As I need to use .NET 4.5, Async support is not available out of the box so is the method I have used for calling my async method correct?
- It appears as though if I have a constructor as in my case, the job does not fire. I have checked and I know the the ITradeExtractor service is registered correctly. So how can I have a job that takes a service in its constructor? If I remove the constructor, my Execute method is called correctly
I am using AutoFac 3.5.2 and Quartz 2.6.2 and AutoFac.Extras.Quartz 3.5.0
I am using the code below to setup AutoFac
public static void RegisterWithAutofac(ContainerBuilder builder)
{
builder.RegisterType<TradeExtractor>()
.As<ITradeExtractor>()
.SingleInstance();
builder.Register(x => new StdSchedulerFactory().GetScheduler()).As<IScheduler>();
}
I know these are old packages, but my limitation of having to use .NET 4.5 means this is out of my control
Paul