0

I have a EventJob class that derived from IJob and EventScheduler class for configuring my job.

public class EventJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {            
            //some code...
        }
    }

public class EventScheduler 
    {
        public ITrigger GetEventTrigger()
        {
            DateTimeOffset startTime = DateBuilder.FutureDate(2, IntervalUnit.Second);
            //Time Scheduling Setting 
            ITrigger eventTrigger = TriggerBuilder.Create()
                .WithIdentity("EventTrigger")
                .StartAt(startTime)
                .WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever())
                .Build();
            return eventTrigger;
        }

        public IJobDetail GetJobDetail()
        {
            //Job Definition Setting
            IJobDetail eventJob = JobBuilder.Create<EventJob>()
                .WithIdentity("EventJob")
                .Build();
            return eventJob;
        }
    }

So, I need add other job that run immediately after current job completed with [DisallowConcurrentExecution] config.

How can I do that?

walen
  • 7,103
  • 2
  • 37
  • 58
S.A
  • 50
  • 14
  • It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check [FAQ](https://stackoverflow.com/tour) and [How to Ask.](https://stackoverflow.com/help/how-to-ask) – Henrik Wilshusen Aug 27 '18 at 13:23
  • Hi @Henrik Wilshusen . Thank you for your advice. but I don't want writing code for my issue. I write it and it works well. so I need add some configuration in Quartz(Scheduler or maybe Trigger class) to run two job as sequential operation. so, on the other hand, my job scheduler is a windows service and does not has an appropriate output to show because it effect on DB directly. so, my issue is how to run two job as sequential job in Quartz.net. – S.A Sep 01 '18 at 08:25

2 Answers2

0

you could achieve this by using IStatefulJob - run both job with the interval you want and it will not run concurrently.

http://quartznet.sourceforge.net/apidoc/

IStatefulJob instances follow slightly different rules from regular IJob instances. The key difference is that their associated JobDataMap is re-persisted after every execution of the job, thus preserving state for the next execution. The other difference is that stateful jobs are not allowed to Execute concurrently, which means new triggers that occur before the completion of the IJob.Execute method will be delayed.

jjj
  • 1,136
  • 3
  • 18
  • 28
  • Thanks @jjj you mean that I should use IStatefulJob instead of IJob interface? If so, when I'm going to use it, it shown as depreciated interface! (Quartz 2.6.1.0). any idea? – S.A Sep 01 '18 at 08:20
-1

Finally after some investigation I found out a good way to accomplished this goal.

It is describe by @Vishal in How to do “sequential” Job Scheduling (Quartz?)

S.A
  • 50
  • 14