public class ERQSJobListener extends ERQSAbstractListener implements org.quartz.JobListener
When a job is candidate to be executed, the job listener posts a notification JOB_WILL_RUN through the NSNotificationCenter. If you want to be notified, subscribe to the JOB_WILL_RUN notification name and read the notification userInfo to know which job will be executed.
When a job has been executed, the job listener posts a notification JOB_RAN through the NSNotificationCenter. Again, if you want to be notified, subscribe to the JOB_WILL_RUN notification name and read the notification userInfo to know which job. If the job fails, we can also get the exception from the userInfo with the key EXCEPTION_KEY.
Depending on the nature of the job description, you have to check the following keys when you access to the userInfo:
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_MAIL_ERROR_MESSAGE_TEMPLATE |
static String |
DEFAULT_MAIL_MESSAGE_WITH_MORE_INFOS_TEMPLATE |
static String |
DEFAULT_MAIL_SHORT_MESSAGE_TEMPLATE |
static String |
DEFAULT_MAIL_SUBJECT_TEMPLATE |
static String |
EXCEPTION_KEY |
static String |
JOB_RAN |
static String |
JOB_WILL_RUN |
log
Constructor and Description |
---|
ERQSJobListener(ERQSSchedulerServiceFrameworkPrincipal schedulerFPInstance) |
Modifier and Type | Method and Description |
---|---|
protected com.webobjects.foundation.NSTimestamp |
dateToNSTimestamp(Date date)
Utility method.
|
protected String |
formattedDuration(long duration)
Return a string used by the logger and the mail sending method.
|
protected String |
getMailContent(org.quartz.JobExecutionContext jobexecutioncontext,
String errorMsg)
Return the mail content.
|
protected String |
getMailSubject(org.quartz.JobExecutionContext jobexecutioncontext)
Return the mail subject.
|
String |
getName()
This method is due to JobListener interface.
|
void |
jobExecutionVetoed(org.quartz.JobExecutionContext jobexecutioncontext)
This method is due to JobListener interface.
|
void |
jobToBeExecuted(org.quartz.JobExecutionContext jobexecutioncontext)
This method is due to JobListener interface.
|
void |
jobWasExecuted(org.quartz.JobExecutionContext jobexecutioncontext,
org.quartz.JobExecutionException jobexecutionexception)
This method is due to JobListener interface.
|
protected ERXLocalizer |
localizer() |
protected void |
logResult(org.quartz.JobExecutionContext jobexecutioncontext,
String errorMsg)
If log info is enabled, logResult logs informations about the job execution like the job duration.
|
protected NSArray<String> |
recipients(org.quartz.JobExecutionContext jobexecutioncontext,
boolean jobRanSuccessfully)
Return a list of recipients depending on the good or bad execution of the job.
|
protected void |
sendMail(String subject,
String textContent,
NSArray<String> recipients)
Sends an plain text email to:
the recipients passed as parameters.
|
protected void |
updateJobDescription(org.quartz.JobExecutionContext jobexecutioncontext,
ERQSJobDescription jobDescription)
Update the first, last and next execution date attributes of jobDescription
|
editingContext, getJobDescription, getSchedulerFPInstance
public static String JOB_WILL_RUN
public static String JOB_RAN
public static String EXCEPTION_KEY
public static final String DEFAULT_MAIL_SUBJECT_TEMPLATE
public static final String DEFAULT_MAIL_ERROR_MESSAGE_TEMPLATE
public static final String DEFAULT_MAIL_SHORT_MESSAGE_TEMPLATE
public static final String DEFAULT_MAIL_MESSAGE_WITH_MORE_INFOS_TEMPLATE
public ERQSJobListener(ERQSSchedulerServiceFrameworkPrincipal schedulerFPInstance)
public String getName()
getName
in interface org.quartz.JobListener
public void jobExecutionVetoed(org.quartz.JobExecutionContext jobexecutioncontext)
Called by the Scheduler when a JobDetail was about to be executed (an associated Trigger has occured),
but a TriggerListener vetoed it's execution.
The method is empty.
jobExecutionVetoed
in interface org.quartz.JobListener
public void jobToBeExecuted(org.quartz.JobExecutionContext jobexecutioncontext)
Called by the Scheduler when a JobDetail is about to be executed (an associated Trigger has occurred).
Posts the notification JOB_WILL_RUN and a userInfo with a global ID if the key is ERQSJob.ENTERPRISE_OBJECT_KEY or directly the ERQSJobDescription object with the key ERQSJob.NOT_PERSISTENT_OBJECT_KEY
jobToBeExecuted
in interface org.quartz.JobListener
public void jobWasExecuted(org.quartz.JobExecutionContext jobexecutioncontext, org.quartz.JobExecutionException jobexecutionexception)
It retrieve the ERQSJobDescription object from the datamap and updates the object.
It also send an email if er.quartzscheduler.ERQSJobListener.sendingmail=true
jobWasExecuted
in interface org.quartz.JobListener
recipients(JobExecutionContext, boolean)
protected NSArray<String> recipients(org.quartz.JobExecutionContext jobexecutioncontext, boolean jobRanSuccessfully)
er.quartzscheduler.ERQSJobListener.executionWithSuccess.to
if any
er.quartzscheduler.ERQSJobListener.executionWithError.to
if any
jobexecutioncontext
- jobRanSuccessfully
- ERQSJobDescription.recipients(boolean)
protected void updateJobDescription(org.quartz.JobExecutionContext jobexecutioncontext, ERQSJobDescription jobDescription)
jobexecutioncontext
- jobDescription
- protected void logResult(org.quartz.JobExecutionContext jobexecutioncontext, String errorMsg)
But if something wrong happened, the log displays the message errorMsg
.
jobexecutioncontext
- errorMsg
- protected String getMailSubject(org.quartz.JobExecutionContext jobexecutioncontext)
An interesting improvement will be to use a localized template. Currently, the default message is:
Job info: JobGroup.MyBeautifullJob is done.
jobexecutioncontext
- (used to build the job full name)protected String getMailContent(org.quartz.JobExecutionContext jobexecutioncontext, String errorMsg)
An interesting improvement will be to use a localized template. Currently, the default content is:
More informations:blabla. It took 90s. if the job returns additional informations or just
It took 90s.
jobexecutioncontext
- (used to get the job duration)errorMsg
- protected void sendMail(String subject, String textContent, NSArray<String> recipients)
subject
- textContent
- recipients
- IllegalStateException
- if from email is empty and the is no recipient at all.protected String formattedDuration(long duration)
If the duration is less than 180s, the duration is expressed in seconds otherwise there is a conversion in mn.
duration
- protected com.webobjects.foundation.NSTimestamp dateToNSTimestamp(Date date)
date
- protected ERXLocalizer localizer()
Copyright © 2002 – 2020 Project Wonder.