I have sceheduled few quartz jobs and triggers for each job, and im using Database store to store the job details and i use simple triggers. I'm using Azure multiple instance. The jobs are scheduled properly, but sometimes the triggers are not firing and the trigger status is "error" and its an intermitent issue. In the console i see the exception as follows,
A first chance exception of type 'System.ArgumentException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
A first chance exception of type 'Quartz.SchedulerException' occurred in Quartz.dll
Could anyone please help me solve the issue? Thanks
EDIT:
Im using ninject to open the Isession when the service starts as follows:
private void InitService() {
IKernel kernel = CreateKernel();
_intraClockAuctionService = kernel.Get<IIntraClockAuctionService>();
}
private IKernel CreateKernel() { var kernel = new StandardKernel();
kernel.Bind<ISessionFactory>().ToProvider<SessionFactoryBuilder>().InSingletonScope();
kernel.Bind<ISession>().ToMethod(context => context.Kernel.Get<ISessionFactory>().OpenSession())
.InCallScope();
kernel.Bind(typeof(IRepository<>)).To(typeof(Repository<>));
kernel.Bind<IJobFactory>().To<JobFactory>();
kernel.Bind<Func<Type, IJob>>().ToConstant(new Func<Type, IJob>(type => (IJob)kernel.Get(type)));
kernel.Bind<ISchedulerFactory>().ToConstant(new StdSchedulerFactory(GetQuartzProperties()));
kernel.Bind<MembershipProvider>().ToConstant(Membership.Providers["DefaultMembershipProvider"]);
kernel.Bind<IMembershipService>().To<AccountMembershipService>();}
and i create my job class as follows:
[DisallowConcurrentExecution]
public class AuctionActivateJob : IJob
{
private readonly ISession _session;
private readonly IAuctionService _auctionService;
private readonly JobManager _jobManager;
private readonly List<IScheduler> _schedulers = new List<IScheduler>();
public AuctionActivateJob(ISession session, JobManager jobManager, IAuctionService auctionService)
{
Utils.LogUtils.LogEvent("inside AuctionActivateJob");
_session = session;
_auctionService = auctionService;
_jobManager = jobManager;
}
public void Execute(IJobExecutionContext context)
{
try
{
SessionTransaction.BeginTransation(_session);
var auctionId = (int)context.MergedJobDataMap["AuctionId"];
var auction = _auctionService.GetAuction(auctionId);
LogUtils.LogEvent(auction.AuctionId + "_Activation starts:" + DateTime.Now);
_auctionService.ActivationStart(auction.AuctionId);
LogUtils.LogEvent(auction.AuctionId + "_Activation ends:" + DateTime.Now);
SessionTransaction.CommitTrans(_session);
}
catch (Exception e)
{
LogUtils.LogException(e);
Email.GenerateServiceExceptionEmail(e);
if (_session.Transaction != null && _session.Transaction.IsActive)
{
_session.Transaction.Dispose();
}
}
}
}
}
and i have common class to add job as
public class JobManager
{
private readonly IJobFactory _jobFactory;
private readonly ISchedulerFactory _schedulerFactory;
public JobManager(ISchedulerFactory schedulerFactory, IJobFactory jobFactory)
{
_schedulerFactory = schedulerFactory;
_jobFactory = jobFactory;
}
public IScheduler Add<T>(ITrigger trigger) where T : IJob
{
string name = trigger.Key.Name;
IScheduler scheduler = _schedulerFactory.GetScheduler();
try
{
scheduler.JobFactory = _jobFactory;
scheduler.Start();
var jobName = typeof (T).Name + "_" + name;
var jobDetail = new JobDetailImpl(jobName, typeof (T));
var isScheduled = scheduler.CheckExists(new JobKey(jobName));
Utils.LogUtils.LogEvent("isScheduled in quartz: " + isScheduled);
if (isScheduled)
return null;
scheduler.ScheduleJob(jobDetail, trigger);
}
catch (JobPersistenceException exception)
{
Utils.LogUtils.LogException(exception);
return null;
//do not do anything
}
catch (Exception ex)
{
Utils.LogUtils.LogException(ex);
return null;
}
return scheduler;
}
public class AuctionManagementService : IAuctionManagementService { private static readonly TimeSpan SchedulePoolingInterval = TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings["SchedulePoolingInter val"]));
private readonly string _appName = ConfigurationManager.AppSettings["AppName"];
private readonly Timer _eventTimer;
private readonly ISession _session;
private readonly IAuctionService _auctionService;
private readonly JobManager _jobManager;
private readonly List<IScheduler> _schedulers = new List<IScheduler>();
private readonly ISchedulerFactory _schedularFactory;
public AuctionManagementService(ISession session, JobManager jobManager, IAuctionService auctionService, ISchedulerFactory schedulerFactory)
{
try
{
_session = session;
_eventTimer = new Timer();
_eventTimer.Elapsed += Refresh;
_eventTimer.Interval = SchedulePoolingInterval.TotalMilliseconds;
_jobManager = jobManager;
_auctionService = auctionService;
_schedularFactory = schedulerFactory;
_schedulers.Add(_schedularFactory.GetScheduler());
}
catch (Exception ex)
{
LogUtils.LogEvent(ex.Message + ex.StackTrace);
Utils.Email.GenerateServiceExceptionEmail(ex);
}
}