Add getScheduledItem() to ScheduledItemError

This commit is contained in:
Travis Burtrum 2014-11-14 11:48:37 -05:00
parent 0af7316873
commit 01d201aaf1
2 changed files with 33 additions and 7 deletions

View File

@ -20,6 +20,7 @@
package com.moparisthebest.jbgjob.processor;
import com.moparisthebest.jbgjob.ScheduledItem;
import com.moparisthebest.jbgjob.ScheduledItemExecutor;
import com.moparisthebest.jbgjob.result.ExecutionResult;
import redis.clients.jedis.Jedis;
@ -105,8 +106,14 @@ public class RedisErrorQueueThread extends RedisProcessingQueueThread {
Jedis jedis = null;
try {
jedis = pool.getResource();
ScheduledItem scheduledItem = null;
try {
scheduledItem = om.readValue(scheduledItemString, ScheduledItem.class);
} catch(Throwable e1) {
// ignore, it'll just stay null
}
// push to error queue
final String error = om.writeValueAsString(new ScheduledItemError(e, scheduledItemString));
final String error = om.writeValueAsString(new ScheduledItemError(e, scheduledItemString, scheduledItem));
if (debug) System.out.printf("redis> LPUSH %s \"%s\"\n", errorQueue, error);
jedis.lpush(errorQueue, error);
// remove from processing queue

View File

@ -20,22 +20,36 @@
package com.moparisthebest.jbgjob.processor;
import com.moparisthebest.jbgjob.ScheduledItem;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Represents an Exception and a serialized ScheduledItem to put in the Redis error queue
* Represents an Exception, the serialized ScheduledItem from Redis, and the attempt to parse it into a ScheduledItem, to put in the Redis error queue
*/
public class ScheduledItemError {
private final long date = System.currentTimeMillis();
private final String exception;
private final String scheduledItemString;
private final ScheduledItem scheduledItem;
public ScheduledItemError(final Throwable e, final String scheduledItemString) {
public ScheduledItemError() {
this.exception = null;
this.scheduledItemString = null;
this.scheduledItem = null;
}
public ScheduledItemError(final Throwable e, final String scheduledItemString, final ScheduledItem scheduledItem) {
this.scheduledItemString = scheduledItemString;
final StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
this.exception = sw.toString();
this.scheduledItem = scheduledItem;
if(e == null) {
this.exception = null;
} else {
final StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
this.exception = sw.toString();
}
}
public long getDate() {
@ -50,12 +64,17 @@ public class ScheduledItemError {
return scheduledItemString;
}
public ScheduledItem getScheduledItem() {
return scheduledItem;
}
@Override
public String toString() {
return "ScheduledItemError{" +
"date=" + date +
", exception='" + exception + '\'' +
", scheduledItemString='" + scheduledItemString + '\'' +
"} " + super.toString();
", scheduledItem=" + scheduledItem +
'}';
}
}