Quartz Job异常

时间:2014-04-24 01:26:16

标签: quartz.net

我为每个作业编写了几个石英作业和触发器,我使用数据库存储来存储作业详细信息,并使用简单的触发器。我使用的是Azure多实例。作业已正确安排,但有时触发器未触发,触发状态为“错误”#34;这是一个间歇性的问题。在控制台中,我看到如下例外,

  

类型' System.ArgumentException'的第一次机会异常。发生在Quartz.dll中   类型' Quartz.SchedulerException'的第一次机会异常发生在Quartz.dll中   类型' Quartz.SchedulerException'的第一次机会异常发生在Quartz.dll

有人可以帮我解决这个问题吗?感谢

编辑:

我在服务开始时使用ninject打开Isession,如下所示:

  

private void InitService()           {

        IKernel kernel = CreateKernel();
        _intraClockAuctionService = kernel.Get<IIntraClockAuctionService>();
    }
  

私有内核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>();}

我按如下方式创建我的工作类:

  

[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();
            }
        }
    }
}

}

我有一个公共类来添加作业

公共类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;
    }
  

公共类AuctionManagementService:IAuctionManagementService       {           private static readonly TimeSpan SchedulePoolingInterval =   TimeSpan.FromSeconds(Convert.ToInt32(ConfigurationManager.AppSettings [&#34; SchedulePoolingInter   VAL&#34;]));

    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);
        }

    }

1 个答案:

答案 0 :(得分:0)

某些参数传递为null,可能是作业调度,在传递给方法调用之前检查null。

需要示例代码才能解决。