Add getScheduledItem() to ScheduledItemError
This commit is contained in:
parent
0af7316873
commit
01d201aaf1
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
package com.moparisthebest.jbgjob.processor;
|
package com.moparisthebest.jbgjob.processor;
|
||||||
|
|
||||||
|
import com.moparisthebest.jbgjob.ScheduledItem;
|
||||||
import com.moparisthebest.jbgjob.ScheduledItemExecutor;
|
import com.moparisthebest.jbgjob.ScheduledItemExecutor;
|
||||||
import com.moparisthebest.jbgjob.result.ExecutionResult;
|
import com.moparisthebest.jbgjob.result.ExecutionResult;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
@ -105,8 +106,14 @@ public class RedisErrorQueueThread extends RedisProcessingQueueThread {
|
|||||||
Jedis jedis = null;
|
Jedis jedis = null;
|
||||||
try {
|
try {
|
||||||
jedis = pool.getResource();
|
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
|
// 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);
|
if (debug) System.out.printf("redis> LPUSH %s \"%s\"\n", errorQueue, error);
|
||||||
jedis.lpush(errorQueue, error);
|
jedis.lpush(errorQueue, error);
|
||||||
// remove from processing queue
|
// remove from processing queue
|
||||||
|
@ -20,22 +20,36 @@
|
|||||||
|
|
||||||
package com.moparisthebest.jbgjob.processor;
|
package com.moparisthebest.jbgjob.processor;
|
||||||
|
|
||||||
|
import com.moparisthebest.jbgjob.ScheduledItem;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
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 {
|
public class ScheduledItemError {
|
||||||
private final long date = System.currentTimeMillis();
|
private final long date = System.currentTimeMillis();
|
||||||
private final String exception;
|
private final String exception;
|
||||||
private final String scheduledItemString;
|
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;
|
this.scheduledItemString = scheduledItemString;
|
||||||
final StringWriter sw = new StringWriter();
|
this.scheduledItem = scheduledItem;
|
||||||
e.printStackTrace(new PrintWriter(sw));
|
if(e == null) {
|
||||||
this.exception = sw.toString();
|
this.exception = null;
|
||||||
|
} else {
|
||||||
|
final StringWriter sw = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(sw));
|
||||||
|
this.exception = sw.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDate() {
|
public long getDate() {
|
||||||
@ -50,12 +64,17 @@ public class ScheduledItemError {
|
|||||||
return scheduledItemString;
|
return scheduledItemString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScheduledItem getScheduledItem() {
|
||||||
|
return scheduledItem;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ScheduledItemError{" +
|
return "ScheduledItemError{" +
|
||||||
"date=" + date +
|
"date=" + date +
|
||||||
", exception='" + exception + '\'' +
|
", exception='" + exception + '\'' +
|
||||||
", scheduledItemString='" + scheduledItemString + '\'' +
|
", scheduledItemString='" + scheduledItemString + '\'' +
|
||||||
"} " + super.toString();
|
", scheduledItem=" + scheduledItem +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user