diff --git a/src/main/java/net/greghaines/jesque/worker/WorkerImpl.java b/src/main/java/net/greghaines/jesque/worker/WorkerImpl.java index 8786c5a0..f7b6ff34 100644 --- a/src/main/java/net/greghaines/jesque/worker/WorkerImpl.java +++ b/src/main/java/net/greghaines/jesque/worker/WorkerImpl.java @@ -216,10 +216,7 @@ public void run() { this.jedis.sadd(key(WORKERS), this.name); this.jedis.set(key(WORKER, this.name, STARTED), new SimpleDateFormat(DATE_FORMAT).format(new Date())); this.listenerDelegate.fireEvent(WORKER_START, this, null, null, null, null, null); - this.popScriptHash.set(this.jedis.scriptLoad(ScriptUtils.readScript(POP_LUA))); - this.lpoplpushScriptHash.set(this.jedis.scriptLoad(ScriptUtils.readScript(LPOPLPUSH_LUA))); - this.multiPriorityQueuesScriptHash - .set(this.jedis.scriptLoad(ScriptUtils.readScript(POP_FROM_MULTIPLE_PRIO_QUEUES))); + loadRedisScripts(); poll(); } catch (Exception ex) { LOG.error("Uncaught exception in worker run-loop!", ex); @@ -539,6 +536,11 @@ protected void recoverFromException(final String curQueue, final Exception ex) { } else { authenticateAndSelectDB(); LOG.info("Reconnected to Redis"); + try { + loadRedisScripts(); + } catch (IOException e) { + LOG.error("Failed to reload Lua scripts after reconnect", e); + } } break; case TERMINATE: @@ -795,6 +797,13 @@ protected String lpoplpush(final String from, final String to) { return (String) this.jedis.evalsha(this.lpoplpushScriptHash.get(), 2, from, to); } + private void loadRedisScripts() throws IOException { + this.popScriptHash.set(this.jedis.scriptLoad(ScriptUtils.readScript(POP_LUA))); + this.lpoplpushScriptHash.set(this.jedis.scriptLoad(ScriptUtils.readScript(LPOPLPUSH_LUA))); + this.multiPriorityQueuesScriptHash + .set(this.jedis.scriptLoad(ScriptUtils.readScript(POP_FROM_MULTIPLE_PRIO_QUEUES))); + } + /** * {@inheritDoc} */