diff --git a/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/RedisErrorQueueThread.java b/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/RedisErrorQueueThread.java index 9e069fa..c397ce8 100644 --- a/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/RedisErrorQueueThread.java +++ b/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/RedisErrorQueueThread.java @@ -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 diff --git a/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/ScheduledItemError.java b/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/ScheduledItemError.java index 2841fe1..aee6952 100644 --- a/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/ScheduledItemError.java +++ b/redisprocessor/src/main/java/com/moparisthebest/jbgjob/processor/ScheduledItemError.java @@ -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 + + '}'; } }