无法将任何内容保存到Quartz.net ADO存储中

问题描述 投票:0回答:3

只是从Quartz.Net开始。因此,请不要介意菜鸟问题。

我已经搜索过SO,但显然我找不到遇到相同问题的人。我在Quartz.Net ADO存储中使用MySQL。我能够成功运行该服务,还可以使用计划程序触发作业。但是没有任何东西可以将日志写入数据库。我检查了数据库是否通过使用错误的密码来获取,并且Scheduler服务无法启动。因此,服务正在选择商店,但是未记录已解雇的作业。我不确定为什么。

这些是我的Scheduler Service的属性。

  <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的数据库脚本,该脚本随Quartz.Net源文件一起提供。

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

谢谢!

c# quartz.net
3个回答
2
投票

与您的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]“自行清除”。它没有保留完整的历史记录。

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

Note this code in 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);

0
投票

我必须更改GetScheduler才能直接包含属性。不知道为什么不选择在创建窗口服务时定义的属性。

有人可以介意为什么这首先不能起作用,因为理想情况下,当我实例化指向Windows服务所服务的调度程序的调度程序时,必须选择该属性,对吧?

编辑:Neater实现是使用使用配置文件。这让我感到沮丧。对不起,菜鸟问题。

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

0
投票

点网核心,Mysql,Quartz 3.0.7。

就我而言,我可以将触发器和作业保存在表中,但问题不会触发。当我不使用LoadQuartzProperties()时。那么它可以正常工作吗?有人可以告诉我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;
}
© www.soinside.com 2019 - 2024. All rights reserved.