Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload redis scripts on reconnect #143

Merged
merged 3 commits into from
Jul 11, 2018
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 load redis scripts", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Failed to reload Lua scripts after reconnect

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}
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