Skip to content

Commit

Permalink
Merge pull request #143 from VirtusAI/fix100-load-scripts-on-reconnect
Browse files Browse the repository at this point in the history
Reload redis scripts on reconnect
  • Loading branch information
gresrun committed Jul 11, 2018
2 parents a13f905 + 3271117 commit 5ef2310
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/net/greghaines/jesque/worker/WorkerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}
*/
Expand Down

0 comments on commit 5ef2310

Please sign in to comment.