PauseTrigger or wait until complete

1,749 views
Skip to first unread message

Ruan Fourie

unread,
Oct 28, 2013, 7:25:03 AM10/28/13
to quar...@googlegroups.com
Hi there,

I wish to use Quartz.net to send out an x amount of emails every hour.  Basically a job must get triggered and then the job can take anything from a minute to lets say an hour and a half to complete.  I then want the next job to only trigger an hour after the last one has completed.

I thought I can do this by pausing the pausing the trigger and then resuming when it's done but then everything fires at once.

So I thought I can do something like this:

(The minute timer is just for testing. The scheduler is set to fire every 5 seconds)
 
public class EmailJob : IJob
{
public void Execute(IJobExecutionContext context)
{
Debug.WriteLine(DateTime.Now.ToShortTimeString());

context.Scheduler.PauseAll();
System.Threading.Thread.Sleep(60000);
context.Scheduler.ResumeAll();
}
}

After that minute of sleeping, this job will execute a lot of times, all at the same time.

I hope all of that made sense.  Is there a way to do what I want to do with Quartz.net?  Wait for the current job to finish and then schedule the next run x amount of time after that.

Thanks for your time.

Christian Krumm

unread,
Oct 28, 2013, 12:45:27 PM10/28/13
to quar...@googlegroups.com
Hi Ruan,

according to your requirements I whould simply reschedule your job at the end of your Execute method as the next schedule is dependant upon the completion of the last run...

You can set the according value for the delay in milli seconds between the individual job executions in job-datamap and read, parse and use that corresponding value in your Execute Method. You may also use a fixed value of one hour if you want so...

The fact, that your test job gets executed multiple times after the minute of sleeping is because of the missfire instructions.
Have a look at the corresponding documentation. Googling for missfire instruction may also help :-)

You may also want to have a look at the SendMailJob which already comes included into quartz.net
Maybe you can write a job which reads your corresonding recipiants, subjects etc. and schedules the corresponding SendMailJobs. That should be pretty straight forward... If the corresponding email should only be send once, you have to think of marking the individual email to be already scheduled for sending in your datastore.

Cheers
Christian


2013/10/28 Ruan Fourie <summe...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To unsubscribe from this group and stop receiving emails from it, send an email to quartznet+...@googlegroups.com.
To post to this group, send email to quar...@googlegroups.com.
Visit this group at http://groups.google.com/group/quartznet.
For more options, visit https://groups.google.com/groups/opt_out.

Ruan Fourie

unread,
Oct 29, 2013, 5:28:50 AM10/29/13
to quar...@googlegroups.com
Hi Christian,

Thank you very much for your reply.  I didn't even know about SendMailJob.

Thanks once again.  You've been very helpful.

Cheers
Ruan
Reply all
Reply to author
Forward
0 new messages