From 017cdf4252c55fdc3e2fc04bec78cfb3d9eb9976 Mon Sep 17 00:00:00 2001 From: Alex Zhukov Date: Thu, 12 Oct 2017 09:32:10 -0700 Subject: [PATCH] removed bury without reason --- src/main/java/rtalk/RTalk.java | 17 +++++++++++++---- src/test/java/rtalk/RTalkTest.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/rtalk/RTalk.java b/src/main/java/rtalk/RTalk.java index be45fd4..b345e50 100644 --- a/src/main/java/rtalk/RTalk.java +++ b/src/main/java/rtalk/RTalk.java @@ -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; @@ -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 @@ -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(); diff --git a/src/test/java/rtalk/RTalkTest.java b/src/test/java/rtalk/RTalkTest.java index a7ab799..7b622c4 100644 --- a/src/test/java/rtalk/RTalkTest.java +++ b/src/test/java/rtalk/RTalkTest.java @@ -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);