Skip to content

Commit

Permalink
removed bury without reason
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuker committed Oct 12, 2017
1 parent 17a6cca commit 017cdf4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/main/java/rtalk/RTalk.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import static java.util.UUID.randomUUID;
import static java.util.stream.Collectors.toMap;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -566,11 +568,18 @@ public synchronized Response bury(String id, long pri, String reason) {
}
return new Response(NOT_FOUND, id, tube);
}

public Response bury(String id, long pri) {
return bury(id, pri, null);

public synchronized Response bury(String id, long pri, Throwable e) {
if (e != null) {
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
String reason = stringWriter.toString();
return bury(id, pri, reason);
}
return bury(id, pri, "");
}


/**
* The "touch" command allows a worker to request more time to work on a
* job. This is useful for jobs that potentially take a long time, but you
Expand Down Expand Up @@ -862,7 +871,7 @@ protected Jedis getRedis() {
}
try {
long retryMsec = (1 << attempt) * 100L;
System.err.println("retry getRedis in " + retryMsec + " because " + lastError);
System.err.println("retry RTalk.getRedis in " + retryMsec + " because " + lastError);
Thread.sleep(retryMsec);
} catch (InterruptedException e) {
e.printStackTrace();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/rtalk/RTalkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void testPutBuryKickJob() throws Exception {
RTalk rt = new RTalk(jedisPool);
Response put = rt.put(0, 0, 0, "a");
assertEquals(INSERTED, put.status);
assertEquals(BURIED, rt.bury(put.id, 0).status);
assertEquals(BURIED, rt.bury(put.id, 0, "reason").status);
assertEquals(0, rt.statsTube().currentjobsready);
assertEquals(1, rt.statsTube().currentjobsburied);
assertEquals(KICKED, rt.kickJob(put.id).status);
Expand Down

0 comments on commit 017cdf4

Please sign in to comment.