Is it possible to manually fire a trigger (or run a job) in Quartz.NET?

6,453 views
Skip to first unread message

Konstantin Khomoutov

unread,
Oct 7, 2011, 2:29:41 PM10/7/11
to quar...@googlegroups.com
I'm using Quartz.NET 1.0.3 to periodically run a set of jobs (an obvious
thing). These jobs are watched by a job listener, and I want to send a
e-mail message when a job being watched fails. Quartz.NET provides the
SendMailJob class which seems like the right thing to use for my task,
but it's a job itself, so now I need a way to somehow execute it
voluntarily. Three ways to do this come to mind:
1) Get a trigger using TriggerUtils.MakeImmediateTrigger() and add it
to the scheduler with an appropriate JobDef each time I need to send
a e-mail message. I'm not sure, but since I see no obvious way to
fire a trigger by hand, I'll possibly need to make this trigger
instance volatile so that it's cleaned up after firing its job.
2) Create some sort of a trigger once, then somehow call it manually
each time I need my SendMailJob run. This would save a trigger
creation each time I need the job to run. It's really like point (1)
with a non-volatile trigger.
3) Do not use triggers at all, instead, create an instance of
SendMailJob manually and somehow execute it when needed. I suspect
this isn't really possible as from the apidoc I got the feeling the
jobs are designed to be run specifically by the scheduler (using its
internal thread pool and other stuff).

I would be glad to hear comments on the points presented or other/better
ways to implement what I need.

Jay Vilalta

unread,
Oct 10, 2011, 11:27:47 AM10/10/11
to quar...@googlegroups.com
Hi Knostantin.

Option 1 is what I have used in the past.

I don't think option 2 is an option, since the triggers are fired by the scheduler, not directly by you.

There's no way to schedule a job without a trigger. You can of course call into the Execute method of the job directly by passing in the parameters directly, effectively running the send mail job from your code.

J



--
You received this message because you are subscribed to the Google Groups "Quartz.NET" group.
To post to this group, send email to quar...@googlegroups.com.
To unsubscribe from this group, send email to quartznet+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/quartznet?hl=en.


Jason Meckley

unread,
Oct 12, 2011, 9:12:50 AM10/12/11
to quar...@googlegroups.com
why not schedule a sendmailjob to fire immediately after completing the original job.

class myjob:ijob
{
   Execute()
   {
        //do my work
        scheduler.scheduler(new sendmailjob(), trigger to fire immediately);
   }
}

the other option, since sending an email is easy, is to simply send the email as part of the job.
new SmtpClient(host, port).Send(to, from, subject, body);

in either case, trying to manually trigger a job seems like you're working against the framework, rather than with the framework.

Penner, Matthew

unread,
Oct 12, 2011, 12:21:50 PM10/12/11
to quar...@googlegroups.com

I would also like a feature like this but I don’t see this really being a part of the framework but something you would design in your app itself.  You could have some process (a button on a WPF form, a button in a web app, etc) that would create a trigger for the job and fire it right then.

 

I use CrystalQuartz, which is an embedded dashboard for web apps for Quartz.Net.  They don’t have this functionality but it is something I’ve through about adding.

 

Matt Penner
Network Engineer II

Val Verde Unified School District

mpe...@valverde.edu
(951) 940-6100 x10709

--

You received this message because you are subscribed to the Google Groups "Quartz.NET" group.

To view this discussion on the web visit https://groups.google.com/d/msg/quartznet/-/v_jkj6TWnwAJ.

Trond Husø

unread,
Nov 3, 2011, 8:11:39 AM11/3/11
to Quartz.NET
Not knowing Quartz.Net that well, but just answering from the top of
my head.
If you did a try catch around the job. If it causes an exception (aka
fails), then put an email alert there?
if this is possible of course.
Or create a try/catch in the job that are to be executed, and mail the
output of catch so that you know that this job didn't finish or get
it's job done.

Trond


On Oct 12, 5:21 pm, "Penner, Matthew" <mpen...@valverde.edu> wrote:
> I would also like a feature like this but I don't see this really being
> a part of the framework but something you would design in your app
> itself.  You could have some process (a button on a WPF form, a button
> in a web app, etc) that would create a trigger for the job and fire it
> right then.
>
> I use CrystalQuartz, which is an embedded dashboard for web apps for
> Quartz.Net.  They don't have this functionality but it is something I've
> through about adding.
>
> Matt Penner
> Network Engineer II
>
> Val Verde Unified School District
>
> mpen...@valverde.edu
> (951) 940-6100 x10709
>
> From: quar...@googlegroups.com [mailto:quar...@googlegroups.com] On
> Behalf Of Jason Meckley
> Sent: Wednesday, October 12, 2011 6:13 AM
> To: quar...@googlegroups.com
> Subject: [quartznet:2682] Re: Is it possible to manually fire a trigger
> (or run a job) in Quartz.NET?
>
> why not schedule a sendmailjob to fire immediately after completing the
> original job.
>
> class myjob:ijob
> {
>    Execute()
>    {
>         //do my work
>         scheduler.scheduler(new sendmailjob(), trigger to fire
> immediately);
>    }
>
> }
>
> the other option, since sending an email is easy, is to simply send the
> email as part of the job.
> new SmtpClient(host, port).Send(to, from, subject, body);
>
> in either case, trying to manually trigger a job seems like you're
> working against the framework, rather than with the framework.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Quartz.NET" group.
> To view this discussion on the web visithttps://groups.google.com/d/msg/quartznet/-/v_jkj6TWnwAJ.
Reply all
Reply to author
Forward
0 new messages