Created
December 4, 2013 16:50
-
-
Save cfalzone/7791020 to your computer and use it in GitHub Desktop.
Extended Quartz Job with a report function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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