[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
scheduler to send email  XML
Forum Index -> Quartz
Author Message
fachhoch

neo

Joined: 01/13/2010 13:12:18
Messages: 3
Offline

I am using quartz to run my jobs.
Right now I have the code to send me email in case any exception occurs in my job ,I am wondering If I can move this code to scheduler ,that way all my jobs need not have the code to send email in case of exceptions ?
Please suggest is there nay method which I can override to implement this?
solid

journeyman

Joined: 01/12/2010 10:52:03
Messages: 15
Offline

if you have over jobs' source files why not just create a parent abstract class that invokes the execute method on all your jobs and catches the exceptions

Why not write something like:
Code:
 public abstract class ManagedJob  implements Job
 {
  
  
     public void execute( JobExecutionContext jobExecContext ) throws JobExecutionException
     {
         try
         {
              executeRealWork(jobExecContext );
         }
         catch( Exception e )
         {
             ManagementBusinesiness.emailAdmin(jobExecContext );
         }
  
     }
  
     public abstract Boolean executeRealWork(JobExecutionContext jobExecContext  );
 }
 

And then you just have to change all your jobs to extend this one and change the execute() to executeRealWork() in your individual job classes.

Another alternative to use and AOP crosscut against all Jobs, This might be a more declarative way of handling it abd would likely result in less code changes. but I have never done so I can't really comment on ease or difficulty.
jhouse

seraphim
[Avatar]
Joined: 11/06/2009 15:29:56
Messages: 1703
Offline


You could use a JobListener and catch the exception events, via the method:

Code:
public void jobWasExecuted(JobExecutionContext inContext,
             JobExecutionException inException)


... which will have non-null exception parameter if the job threw one.
 
Forum Index -> Quartz
Go to:   
Powered by JForum 2.1.7 © JForum Team