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

本文关键字:Quartz net ado 存储 保存 任何内 | 更新日期: 2023-09-27 18:06:07

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

我已经搜索了SO,但显然,我找不到面临同样问题的人。我使用MySQL为我的石英。Net ADO存储。我能够成功地运行服务,并使用调度器触发作业。但是没有任何东西将日志记录到数据库中。我检查了DB是否通过使用错误的密码而被拾取,并且Scheduler服务未能启动。因此,服务正在挑选Store,但被触发的作业没有被记录。我不知道为什么。

这些是我的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!");
        }
    }

我用DB脚本为MySQL创建ADOStore,这是随Quartz一起来的。Net源文件。

我做错了什么吗?请给我指路。

谢谢!

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

比较我的工作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);

我必须更改我的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;
            }
        }

Dot Net core, 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;
}