Quartz.Net Listeners in Detail – Part 1

This post is the first post of a series called the Quartz.Net Listener Tutorial. Today we’ll be introducing you to listeners in detail. We’ll cover what they are and what they could be used for. Part 1 will only cover listeners in general. Parts 2-4 will cover the details of the specific types of listeners.

What are Quartz.Net listeners?

Quartz.Net listeners are objects that can be notified when certain events happen inside a Quartz.Net scheduler. There are 3 types of listeners:

  • Scheduler listeners
  • Job listeners
  • Trigger listeners

Let’s look at each of these listeners in more detail.

Scheduler Listeners

Scheduler listeners are used when you want to be notified of scheduler level events. What are scheduler level events? There are quite a few, so I’ve grouped them by the object to which they apply. I think the descriptions are quite descriptive but if you need more detailed information for each of these events, check out the book or the subsequent posts.

Job Events

  • A job was added
  • A job was deleted
  • A job was scheduled
  • A job was unscheduled
  • A job was paused
  • A job was resumed
  • Several jobs were paused
  • Several jobs were resumed

Trigger Events

  • A trigger was finalized
  • A trigger was paused
  • A trigger was resumed
  • Several triggers were paused
  • Several triggers were resumed

Scheduler Events

  • The scheduler is starting
  • The scheduler started
  • The scheduler is shutting down
  • The scheduler has shut down
  • The scheduler has moved to standby mode
  • There was a scheduler error
  • The scheduler’s scheduling data has been cleared

Scheduler listeners must implement the ISchedulerListener interface.

When would I use scheduler listeners?

In general, scheduler level events can be quite useful if you need to keep track or audit changes made to the scheduler and the schedule. Being notified of errors is also useful to monitor possible issues with the scheduler itself.

Job Listeners

Job listeners are used when you want to be notified of job level events. Here’s a list of the events that are supported at the job level:

  • A job’s execution was vetoed
  • A job is about to be executed
  • A job was executed

Job listeners must implement the IJobListener interface

When would I use job listeners?

My favorite use for job listeners is to keep track of how long it takes a given job to run and to monitor that run time duration.

Trigger Listeners

Trigger listeners are used when you want to be notified of trigger level events. Triggers will raise the following events:

  • A trigger has fired
  • A trigger has misfired
  • A trigger has completed
  • Should we veto this execution?

You’ll notice that last event is a bit unusual. We’ll cover that one when we get to trigger listeners post. Trigger listeners must implement the ITriggerListener interface.

When would I use Trigger listeners?

If you want to be able to stop a regularly scheduled job from running, you’ll need to use a trigger listener to veto that execution. Tracking misfires is useful as well to make sure your scheduler is healthy and that things are running within reason.

Up Next

I hope this gives you a good overview of how listeners work in Quartz.Net and what you could do with them. In Part 2 we’ll cover scheduler listeners in more detail.