question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When use AdoJobStore.JobStoreTX jobs not firing

See original GitHub issue

Version: alpha 3.0

Expected behavior

Jobs have to be fired in specified time

Actual behavior

Nothing happens

Steps to reproduce

Scheduler Factory (Singletone):

public class SchedulerFactory : ISchedulerFactory
    {
        private StdSchedulerFactory _schedulerFactory { get; set; }

        private IScheduler _scheduler { get; set; }

        public IScheduler Get()
        {
            if (_scheduler == null)
            {
                if (_schedulerFactory == null)
                {
                    _schedulerFactory = new StdSchedulerFactory(new NameValueCollection
                    {
                        ["quartz.scheduler.instanceName"] = "Scheduler",
                        ["quartz.scheduler.instanceId"] = "main",
                        ["quartz.threadPool.type"] = "Quartz.Simpl.SimpleThreadPool, Quartz",
                        ["quartz.threadPool.threadCount"] = "10",
                        ["quartz.threadPool.threadPriority"] = "Normal",
                        ["quartz.jobStore.misfireThreshold"] = "60000",
                        ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
                        ["quartz.jobStore.useProperties"] = "false",
                        ["quartz.jobStore.dataSource"] = "default",
                        ["quartz.jobStore.tablePrefix"] = "QRTZ_",
                        ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz",
                        ["quartz.jobStore.lockHandler.type"] = "Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz",
                        ["quartz.dataSource.default.connectionString"] = "Data Source=.\\SQLEXPRESS;Initial Catalog=QuartzDB;Integrated Security=True;MultipleActiveResultSets=True;",
                        ["quartz.dataSource.default.provider"] = "SqlServer-20",
                        ["quartz.serializer.type"] = "json"
                    });
                }
                _scheduler = _schedulerFactory.GetScheduler().Result;
                _scheduler.Start().Wait();
            }


            return _scheduler;
        }

        public void Dispose()
        {
            if (!_scheduler?.IsShutdown == true)
                _scheduler.Shutdown(false).Wait();
        }
    }

Simple Job:

    public class SendUserEmailsJob : IJob
    {
        public SendUserEmailsJob()
        {
            
        }

        public Task Execute(IJobExecutionContext context)
        {
           return Task.Run(() =>
                           {
                               LoggerUtil.Log("fire job", "SCHEDULER");
                           });
        }
    }

Adding the job:

var adminEmailsJob = JobBuilder.Create<SendUserEmailsJob>()
        .WithIdentity("SendUserEmailsJob")
        .Build();
var adminEmailsTrigger = TriggerBuilder.Create()
        .WithIdentity("UserEmailsTrigger")
        .StartAt(DateTimeOffset.UtcNow.AddDays(-10))
        .WithSimpleSchedule(builder => builder.WithIntervalInSeconds(1).RepeatForever().WithMisfireHandlingInstructionFireNow().Build())
        .Build();

_scheduler.ScheduleJob(adminEmailsJob, adminEmailsTrigger).Wait();

I’ve created DB with tables. It runs without any errors. Get and save jobs/trigges in DB, but doesn’t want to fire any job with any trigger

If I switch quartz.jobStore.type to RAMJobStore everything works fine, but I need to use JobStoreTX to store all info in one place and get it in other.

What is wrong in my config? Could you help me with it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
kongrescommented, Sep 7, 2017

@lahma Thank you I didn’t find info how to attach a logger to Quartz. It helped me to find the problem. So some reason sql script (https://github.com/MassTransit/MassTransit-Quartz/blob/master/setup_sql_server.sql) created damaged QRTZ_FIRED_TRIGGERS and this bug didn’t allow to fire any job. But when I tried to create the DB and run script again then it started to work as expected. I think it was some glitch of SqlClient because I create db and run the script via c# code as initinializator.

Small note about logger. Maybe it will be a bit better to add string.Format for result of func() :

var funcResult = func != null ? string.Format(func(), parameters) : string.Empty;

Thank you again! Now everything works perfect!

0reactions
lahmacommented, Sep 6, 2017

Here’s an example of getting logs to console using custom log provider. Naturally using a logging library would be more wise.

using System;
using System.Threading;
using System.Threading.Tasks;

using Quartz;
using Quartz.Impl;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            Run().GetAwaiter().GetResult();
        }

        private static async Task Run()
        {
            Quartz.Logging.LogProvider.SetCurrentLogProvider(new ConsoleLogProvider());
            ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler sched = await sf.GetScheduler();

            Console.WriteLine("starting");
            await sched.Start();

            Thread.Sleep(TimeSpan.FromMinutes(10));
        }

        private class ConsoleLogProvider : Quartz.Logging.ILogProvider
        {
            public Quartz.Logging.Logger GetLogger(string name)
            {
                return (level, func, exception, parameters) =>
                {
                    string funcResult = func != null ? func() : string.Empty;
                    Console.WriteLine($"{level} {funcResult} {exception}");
                    return true;
                };
            }

            public IDisposable OpenNestedContext(string message)
            {
                throw new NotImplementedException();
            }

            public IDisposable OpenMappedContext(string key, string value)
            {
                throw new NotImplementedException();
            }
        }
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Quartz .net job is not executing
So quartz is not running. IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler(); scheduler.Start();. After starting it the server ...
Read more >
Quartz.NET Configuration Reference
AdoJobStore is used to store scheduling information (job, triggers and calendars) within a relational database. There are actually two separate ...
Read more >
Clustered Quartz Scheduler triggers the same job on two ...
I am using Quartz.net to run eight similar jobs once a minute. A windows service runs each Quartz instance and Quartz is set...
Read more >
Lesson 9: Job Stores
Lesson 9: Job Stores. JobStore's are responsible for keeping track of all the “work data” that you give to the scheduler: jobs, triggers,...
Read more >
Quartz.Net - Job does not wait to finish previous execution ...
When jobs finish as expected, there are no issues at all. Everything works fine, but when I put a delay (Thread.Sleep()) in a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found