【问题标题】:Quartz Job exception石英作业异常
【发布时间】:2014-04-24 01:26:16
【问题描述】:

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

在 Quartz.dll 中发生了“System.ArgumentException”类型的第一次机会异常
Quartz.dll 中出现了“Quartz.SchedulerException”类型的第一次机会异常
Quartz.dll 中出现了“Quartz.SchedulerException”类型的第一次机会异常

谁能帮我解决这个问题?谢谢

编辑:

我使用ninject在服务启动时打开Isession如下:

private void InitService() {

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

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

我创建我的工作类如下:

[禁止并发执行]

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 { 私有静态只读 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);
        }

    }

【问题讨论】:

  • 请务必阅读选择标签时出现的说明!

标签: quartz.net


【解决方案1】:

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

需要示例代码来解决。

【讨论】:

  • 请查看随附的示例代码,如果您想澄清任何事情,请告诉我。正如您所说,Job 构造函数有 3 个参数,Isession、JobManager 和 Auction Service,您是否建议将这些参数中的任何一个 cud 传递为 null?由于我在服务启动时打开会话,我不确定它怎么可能是空的
猜你喜欢
  • 2010-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-08
  • 1970-01-01
  • 2011-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多