使用 ADOStore 运行作业时出现 Quartz.net 错误 [英] Quartz.net error when running job with ADOStore

查看:58
本文介绍了使用 ADOStore 运行作业时出现 Quartz.net 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 asp.net mvc 应用程序中使用quartz.net.

Im using quartz.net in a asp.net mvc application.

尝试将其配置为用户 ADOStore.

Trying to configurate it to user ADOStore.

我已经创建了表格.

NameValueCollection properties = new NameValueCollection();

        properties["quartz.scheduler.instanceName"] = "TestScheduler";
        properties["quartz.scheduler.instanceId"] = "instance_one";
        properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
        // if running MS SQL Server we need this
        properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";

        properties["quartz.dataSource.default.connectionString"] = "Server=.\\SQLExpress;Database=test;Trusted_Connection=True;";
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";

// StdSchedulerFactory
        this.Initialize(properties);

运行应用程序时收到错误消息:

When running the application im getting errormessages:

在 Quartz.dll 中发生了类型为Quartz.ObjectAlreadyExistsException"的第一次机会异常'Quartz.JobPersistenceException' 类型的第一次机会异常发生在 Quartz.dll 中'Quartz.JobPersistenceException' 类型的第一次机会异常发生在 Quartz.dll 中

A first chance exception of type 'Quartz.ObjectAlreadyExistsException' occurred in Quartz.dll A first chance exception of type 'Quartz.JobPersistenceException' occurred in Quartz.dll A first chance exception of type 'Quartz.JobPersistenceException' occurred in Quartz.dll

查看 QRTZ_ 表时,QRTZ_JOB_DETAILS 中有一个职位用于该职位.其他表是空的.

When looking in the QRTZ_ tables QRTZ_JOB_DETAILS has one post in it for the job. The other tables is empty.

知道是什么导致了这里的问题吗?

Any idea whats causing the problem here?

更新:

public class UnitySchedulerFactory : StdSchedulerFactory
{
    private readonly UnityJobFactory unityJobFactory;

    public UnitySchedulerFactory(UnityJobFactory unityJobFactory)
    {
        NameValueCollection properties = new NameValueCollection();

        properties["quartz.scheduler.instanceName"] = "TestScheduler";
        properties["quartz.scheduler.instanceId"] = "instance_one";
        properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
        properties["quartz.jobStore.useProperties"] = "true";
        properties["quartz.jobStore.dataSource"] = "default";
        properties["quartz.jobStore.tablePrefix"] = "QRTZ_";
        // if running MS SQL Server we need this
        properties["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz";

        properties["quartz.dataSource.default.connectionString"] = "Server=.\\SQLExpress;Database=189021;Trusted_Connection=True;";
        properties["quartz.dataSource.default.provider"] = "SqlServer-20";

        this.Initialize(properties);
        this.unityJobFactory = unityJobFactory;
    }

    protected override IScheduler Instantiate(QuartzSchedulerResources rsrcs, QuartzScheduler qs)
    {
        qs.JobFactory = this.unityJobFactory;            
        return base.Instantiate(rsrcs, qs);
    }
}

Global.asax

Global.asax

var scheduler = unityContainer.Resolve<IQuartzScheduler>();
scheduler.Run();

更新 2

这里是整个石英解决方案的链接:

Here is a link to the whole quartz solution:

http://1drv.ms/1o0rpg8

Quartz 表是从以下创建的:

Quartz tables is created from following:

https://github.com/MassTransit/MassTransit-Quartz/blob/master/setup_sql_server.sql

Global.asax:

Global.asax:

var unityContainer = Infrastructure.Bootstrapper.Initialise();

var scheduler = unityContainer.Resolve<IQuartzScheduler>();
scheduler.Run(); 

我正在尝试做的是处理 ADOstore 的误触发,以便系统可以处理重新启动或崩溃.

The thing I'm trying to do is handle the misfiring with ADOstore so that the system can hanlde a restart or a crash.

推荐答案

如果您将作业(正如您所做的那样)持久保存在数据库中,则无法一直创建它们.
您必须在启动时检查它们是否存在.

If you're persisting your jobs (as you do) in a database you cannot create them all the time.
You have to check if they exists at the start-up.

此处查看我的回答以了解更多详细信息.

Check my answer here for more details.

Quartz.Net 被初始化并且您正在使用 AdoJobStore 时,调度程序会获取保存在数据库中的所有作业/触发器.

When Quartz.Net is initialized and you're using AdoJobStore, the scheduler fetches all the jobs/triggers save in the database.

在您的 IQuartzScheduler.Run() 中,您应该检查作业是否存在:

In your IQuartzScheduler.Run() you should check if the job is present:

this.Scheduler.GetJobDetail()

你可以使用这段代码来测试它是否有效:

You can use this bit of code to test if it works:

IJobDetail helloJob = null;
ITrigger helloTrigger = null;

helloJob = this.Scheduler.GetJobDetail(new JobKey("HelloJob", "MyGroup"));

if (helloJob == null)
{
    helloJob = JobBuilder.Create<Jobs.HelloJob>()
        .WithIdentity("HelloJob", "MyGroup")
        .RequestRecovery(true)
        // .StoreDurably(true)
        .Build();

    helloTrigger = TriggerBuilder.Create()
         .WithIdentity("HelloTrigger", "MyGroup")
         .StartNow()
         .WithSimpleSchedule(x => x.RepeatForever().WithIntervalInSeconds(20))
         .Build();

    this.Scheduler.ScheduleJob(helloJob, helloTrigger);
}

this.Scheduler.Start();

如果您使用的是最新的 Quartz.Net 版本,那么数据库创建脚本似乎有问题.

If you're using the latest Quartz.Net version there seem to be a problem with the database creation script.

我注意到触发器不会触发.然后,我使用 GitHub 并且它工作正常.

I've noticed that the triggers don't fire. I've then created the database using the latest scripts from Quartz.Net repository on GitHub and it works properly.

也请查看此答案.Quartz.Net + AdoJobStore 上有更多详细信息.

Check this answer as well. There are few more details on Quartz.Net + AdoJobStore.

这篇关于使用 ADOStore 运行作业时出现 Quartz.net 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆