Skip to content

Instantly share code, notes, and snippets.

@cfalzone
Created December 4, 2013 16:50
Show Gist options
  • Save cfalzone/7791020 to your computer and use it in GitHub Desktop.
Save cfalzone/7791020 to your computer and use it in GitHub Desktop.
Extended Quartz Job with a report function
package com.aquent.quartz;
import java.net.InetAddress;
import org.quartz.Job;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.UtilMethods;
import com.dotmarketing.viewtools.MailerTool;
public abstract class AquentQuartzJob implements Job {
public void report(String subject, String to, String from, int totalItems, int numImported,
int numFailed, String errors, String warnings) {
StringBuilder message = new StringBuilder();
try {
message.append("<b>Job Ran on</b>:"+InetAddress.getLocalHost().getHostName()+"<br /><br />");
} catch(Exception e) {
Logger.warn(this.getClass(), "Unable to get the servers address", e);
}
message.append("<b>Total Items</b>: "+totalItems+"<br />");
message.append("<b>Items Imported</b>: "+numImported+"<br />");
message.append("<b>Items Failed</b>: "+numFailed+"<br /><br />");
if(UtilMethods.isSet(warnings)) {
message.append("<b>Warnings</b>: <ul>" + warnings + "</ul><br />");
}
if(UtilMethods.isSet(errors)) {
subject = "ERROR: "+subject;
message.append("<b>Erros</b>: <ul>" + errors + "</ul><br />");
}
Logger.info(this.getClass(), "Total Items Imported: "+totalItems);
Logger.info(this.getClass(), "Total Items Imported: "+numImported);
Logger.info(this.getClass(), "Total Items Failed: "+numFailed);
MailerTool mailer = new MailerTool();
String resp = mailer.sendEmail(to, from, subject, message.toString(), true);
if(UtilMethods.isSet(resp)) {
Logger.error(this.getClass(), "Unable to send report email: "+resp);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment