0

I have a small background process that serves message sending service built upon Quartz.net lib.

The basic problem is that job trigger instruction .StartNow() starts concurently with the same instances of the current MessageJob.

And I've got no idea how to queue jobs of the same GROUP_NAME to run in FIFO queue one by one.

Here is a tiny sample:

using System;
using Quartz;
using Quartz.Impl;

namespace Messaging
{
    class Program
    {
        static void Main()
        {
            var scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();

            for (var i = 0; i < 10; i++)
            {
                var id = Guid.NewGuid();
                var job = JobBuilder.Create<MessageJob>()
                        .WithIdentity($"job_{id}", "MESSAGING")
                        .UsingJobData("Text", $"message_{i:D3}")
                        .Build();

                var trigger = TriggerBuilder.Create()
                    .WithIdentity($"trigger_{id}", "MESSAGING")
                    .StartNow()
                    .Build();

                scheduler.ScheduleJob(job, trigger);
            }
        }
    }

    public class MessageJob : IJob
    {
        public string Text { get; set; }

        public void Execute(IJobExecutionContext context)
        {
            var key = context.JobDetail.Key;
            Console.WriteLine($"job \'{key}\'. Text: {Text}");
        }
    }
}

This code causes race condition between same jobs of a single type. I would like to achieve next job fire triggering only if previous instance of MessageJob was succesfully executed, in order of scheduler.ScheduleJob(job, trigger); adding.

Ruberoid
  • 1,585
  • 1
  • 9
  • 12
  • have you look on http://stackoverflow.com/questions/24515470/jobs-not-chaining-using-jobchainingjoblistener ? – Set Aug 30 '16 at 07:44
  • Yes, I have. That post guided me to create my own `JobListenerSupport` class that contains `ConcurrentQueue`. For some reason I can't post implementation right now, here, answering my own question. – Ruberoid Aug 31 '16 at 10:58

0 Answers0