【问题标题】:Unable to save anything to the Quartz.net ado store无法将任何内容保存到 Quartz.net ado 商店
【发布时间】:2014-05-30 12:47:20
【问题描述】:

刚开始使用 Quartz.Net。所以请不要介意菜鸟的问题。

我已经搜索过,但显然,我找不到面临同样问题的人。 我将 MySQL 用于我的 Quartz.Net ADO 存储。我能够成功运行服务并使用调度程序触发作业。但是没有任何日志进入数据库。我检查了是否使用错误密码获取了数据库,并且调度程序服务无法启动。因此,服务正在选择商店,但未记录被解雇的工作。我不知道为什么。

这些是我的调度服务的属性。

  <quartz >
    <add key="quartz.scheduler.instanceName" value="AbACScheduler"/>
    <add key="quartz.scheduler.instanceId" value="instance_one"/>
    <add key="quartz.threadPool.threadCount" value="10"/>
    <add key="quartz.threadPool.threadPriority" value="Normal"/>

    <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz"/>
    <add key="quartz.jobStore.dataSource" value="default"/>
    <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
    <add key="quartz.dataSource.default.connectionString" value="Server=localhost;Database=quartz;Uid=xxx;Pwd=xxx;"/>
    <add key="quartz.jobStore.tablePrefix" value="qrtz_"/>
    <add key="quartz.dataSource.default.provider" value="MySql-50"/>
    <add key="quartz.jobStore.useProperties" value="true"/>
  </quartz>

表前缀也正确,我使用的是 5.0 MySQL 连接器。

这是我用于测试服务的小型测试控制台代码。

 private static void Main(string[] args)
    {
        try
        {
            Common.Logging.LogManager.Adapter = new Common.Logging.Simple.ConsoleOutLoggerFactoryAdapter { Level = Common.Logging.LogLevel.Info };

            // Grab the Scheduler instance from the Factory 
            IScheduler scheduler = GetScheduler();

            // and start it off
            scheduler.Start();

            // define the job and tie it to our HelloJob class
            IJobDetail job = JobBuilder.Create<HelloJob>()
                .WithIdentity("job1", "group1")
                .Build();

            // Trigger the job to run now, and then repeat every 10 seconds
            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .StartNow()
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(10)
                    .RepeatForever())
                .Build();

            // Tell quartz to schedule the job using our trigger
            scheduler.ScheduleJob(job, trigger);

            // some sleep to show what's happening
            Thread.Sleep(TimeSpan.FromSeconds(60));

            // and last shut down the scheduler when you are ready to close your program
            scheduler.Shutdown();
        }
        catch (SchedulerException se)
        {
            Console.WriteLine(se);
        }

        Console.WriteLine("Press any key to close the application");
        Console.ReadKey();
    }
    private static IScheduler GetScheduler()
    {
        try
        {
            var properties = new NameValueCollection();
            properties["quartz.scheduler.instanceName"] = "AbACScheduler";
            properties["quartz.dataSource.default.provider"] ="MySql-50";
            properties["quartz.scheduler.proxy.address"] = string.Format(@"tcp://{0}:{1}/{2}", "localhost", "555",
                                                                         "AbACScheduler");

            // Get a reference to the scheduler
            var sf = new StdSchedulerFactory(properties);

            return sf.GetScheduler();

        }
        catch (Exception ex)
        {
            Console.WriteLine("Scheduler not available: '{0}'", ex.Message);
            throw;
        }
    }

这是我的 HelloJob(取自quartz.Net)

public class HelloJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            Console.WriteLine("Greetings from HelloJob!");
        }
    }

我使用了用于为 MySQL 创建 ADOStore 的 DB 脚本,该脚本与 Quartz.Net 源文件一起提供。

有什么我做错了吗?请指导我。

谢谢!

【问题讨论】:

  • 您遇到了什么异常?
  • 我实际上没有得到任何异常。
  • 您说作业没有被记录是什么意思?您希望看到哪些您在数据库中没有看到的内容?
  • 不应该在 qrtz_fired_triggers 中记录一些东西吗?我不知道。我认为 Quartz 应该将其记录在 ADO Store 中,或者将仍在运行的当前作业记录在 qrtz_job_details 中;调度器状态记录在 qrtz_scheduler_state 中;实际上什么也没发生。我错过了什么吗?

标签: c# quartz.net


【解决方案1】:

比较我的工作 AdoJobStore(但使用 sql server)........与你的相比,我发现以下项目丢失。

<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzSchedulerInstanceName"/>
<add key="quartz.scheduler.instanceId" value="instance_one"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="Normal"/>

现在我有了这个:

<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>

你有:

有 MySql 专用的吗?

这是我的完整设置,带有 sql server,但也许你可以从这个开始并插入 mysql 值。

<add key="quartz.scheduler.instanceName" value="ExampleDefaultQuartzSchedulerFromConfigFileSqlServer"/>
<add key="quartz.scheduler.instanceId" value="instance_one"/>
<add key="quartz.threadPool.threadCount" value="10"/>
<add key="quartz.threadPool.threadPriority" value="Normal"/>

<!-- 
org.quartz.scheduler.idleWaitTime
Is the amount of time in milliseconds that the scheduler will wait before re-queries for available triggers when the scheduler is otherwise idle. Normally you should not have to 'tune' this parameter, unless you're using XA transactions, and are having problems with delayed firings of triggers that should fire immediately.
It defaults to every 30 seconds until it finds a trigger. Once it finds any triggers, it gets the time of the next trigger to fire and stops checking until then, unless a trigger changes.   -->
<add key="quartz.scheduler.idleWaitTime" value ="5000"/>

<!-- Misfire : see http://nurkiewicz.blogspot.com/2012/04/quartz-scheduler-misfire-instructions.html  -->
<add key="quartz.jobStore.misfireThreshold" value="60000"/>
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz"/>
<add key="quartz.jobStore.tablePrefix" value="QRTZ_"/>
<add key="quartz.jobStore.clustered" value="false"/>
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz"/>


<add key="quartz.jobStore.dataSource" value="MySqlServerFullVersion"/>
<add key="quartz.jobStore.useProperties" value="false"/>

<add key="quartz.dataSource.MySqlServerFullVersion.connectionString" value="SuperSecret!!"/>
<add key="quartz.dataSource.MySqlServerFullVersion.provider" value="SqlServer-20"/>

编辑

这是我的完整代码……仅供参考。

            NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");
            ISchedulerFactory factory = new StdSchedulerFactory(config);
            IScheduler sched = factory.GetScheduler();

            try
            {

                sched.Clear();

                /* schedule some jobs through code */

                sched.Start();

                Thread.Sleep(TimeSpan.FromSeconds(1));

                Console.WriteLine(string.Empty);
                Console.WriteLine("Press ENTER to Continue to Shut Down");
                Console.WriteLine(string.Empty);
                Console.ReadLine();

            }
            finally
            {
                sched.Shutdown(false);
            }


            Console.Write("");

        }
        catch (Exception ex)
        {

            Exception exc = ex;
            while (null != exc)
            {
                Console.WriteLine(exc.Message);
                exc = exc.InnerException;
            }
        }
        finally
        {
            Console.WriteLine(string.Empty);
            Console.WriteLine(string.Empty);
            Console.WriteLine("Press ENTER to Exit");
            Console.ReadLine();
        }

我刚刚检查过了。 [QRTZ_FIRED_TRIGGERS] “自行清理”。它不会保留完整的历史记录。

我在我的开发环境中运行了数千个作业,但该表中只有一行。

请注意 StdAdoConstants.cs 中的以下代码

        public static readonly string SqlDeleteFiredTrigger =
            string.Format(CultureInfo.InvariantCulture, "DELETE FROM {0}{1} WHERE {2} = {3} AND {4} = @triggerEntryId", 
            TablePrefixSubst, TableFiredTriggers,ColumnSchedulerName, SchedulerNameSubst, ColumnEntryId);

        public static readonly string SqlDeleteFiredTriggers =
            string.Format(CultureInfo.InvariantCulture, "DELETE FROM {0}{1} WHERE {2} = {3}", TablePrefixSubst, TableFiredTriggers, ColumnSchedulerName, SchedulerNameSubst);

        public static readonly string SqlDeleteInstancesFiredTriggers =
            string.Format(CultureInfo.InvariantCulture, "DELETE FROM {0}{1} WHERE {2} = {3} AND {4} = @instanceName", TablePrefixSubst, TableFiredTriggers, ColumnSchedulerName, SchedulerNameSubst,
                          ColumnInstanceName);

【讨论】:

  • 其实MYSQL的委托是Quartz.Impl.AdoJobStore.MySQLDelegate,Quartz。从github.com/quartznet/quartznet/blob/master/src/… 得到它但仍然没有运气。当我运行他的 Job 时,没有任何东西写入 JobStore。
  • 不...没有任何区别。此外,该示例直接取自 Quartz.Net 网站quartz-scheduler.net/documentation/quartz-2.x/quick-start.html
  • 请注意在我的代码中我如何使用 FActory 和 "GetSection("quartz");".....这就是为什么您的代码没有获取配置值的原因吗?
  • 是的,现在说得通了。需要再次传递配置值。一次用于创建 Windows 服务,另一次用于实例化调度程序。但是默认功能不应该是选择创建 Windows 服务时提供的值吗?
  • 是的,没错。配置设置需要传递给调度程序并使用 NamedValueCollection,更简洁的方式。
【解决方案2】:

我不得不更改我的 GetScheduler 以直接包含属性。不知道为什么在创建窗口服务时定义的属性没有被拾取。

有人可以解释一下为什么这首先不起作用,因为理想情况下,当我实例化指向由 Windows 服务提供服务的调度程序的调度程序时,必须获取这些属性,对吗?

编辑:更整洁的实现是使用配置文件。这让我很沮丧。很抱歉这个菜鸟问题。

private static IScheduler GetScheduler()
        {
            try
            {
                var properties = new NameValueCollection();
                properties["quartz.scheduler.instanceName"] = "AbACScheduler";
                properties["quartz.scheduler.instanceId"] = "instance_one";
                properties["quartz.threadPool.threadCount"] = "10";
                properties["quartz.threadPool.threadPriority"] = "Normal";

                properties["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz";
                properties["quartz.jobStore.dataSource"] = "default";
                properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz";
                properties["quartz.dataSource.default.connectionString"] = "Server=localhost;Database=quartz;Uid=xxx;Pwd=xxx;";
                properties["quartz.jobStore.tablePrefix"] = "qrtz_";
                properties["quartz.dataSource.default.provider"] = "MySql-50";
                properties["quartz.jobStore.useProperties"] = "true";
                properties["quartz.scheduler.proxy.address"] = string.Format(@"tcp://{0}:{1}/{2}", "localhost", "555",
                                                                             "AbACScheduler");

                // Get a reference to the scheduler
                var sf = new StdSchedulerFactory(properties);

                return sf.GetScheduler();

            }
            catch (Exception ex)
            {
                Console.WriteLine("Scheduler not available: '{0}'", ex.Message);
                throw;
            }
        }

【讨论】:

    【解决方案3】:

    点网核心、Mysql、Quartz 3.0.7。

    在我的情况下,我可以将触发器和作业保存在表中,但问题触发器没有命中。当我不使用LoadQuartzProperties().then 工作正常时,谁能告诉我LoadQuartzProperties() 方法有什么问题?

     private NameValueCollection LoadQuartzProperties()
    
    {
    
                var NameValueCollection = new NameValueCollection();
                NameValueCollection.Add("quartz.scheduler.instanceName", "HomeScheduler");
                NameValueCollection.Add("quartz.scheduler.instanceId", "Instance");
                NameValueCollection.Add("quartz.jobStore.type", "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz");
                NameValueCollection.Add("quartz.jobStore.driverDelegateType", "Quartz.Impl.AdoJobStore.MySQLDelegate, Quartz");
                NameValueCollection.Add("quartz.jobStore.useProperties", "false");
                NameValueCollection.Add("quartz.jobStore.dataSource", "Home");
                NameValueCollection.Add("quartz.jobStore.tablePrefix", "QRTZ_");
                NameValueCollection.Add("quartz.dataSource.Home.provider", "MySql");
                NameValueCollection.Add("quartz.dataSource.Home.connectionString", "server=ser...;database=...;user=...;pwd=...;TreatTinyAsBoolean=false");
                NameValueCollection.Add("quartz.threadPool.threadCount", "50");
                NameValueCollection.Add("quartz.threadPool.threadPriority", "10");
                NameValueCollection.Add("quartz.serializer.type", "json");           
                return NameValueCollection;
    }
    

    【讨论】:

    • 很抱歉,您是否使用 await scheduler.Start(); 启动调度程序?给出运行调度程序的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-12
    • 1970-01-01
    • 2021-03-13
    • 2020-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多