Skip to content

Commit

Permalink
pre-init doCluster callback before writing to redis
Browse files Browse the repository at this point in the history
  • Loading branch information
evantahler committed Aug 23, 2018
1 parent 11ee939 commit 651f86b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions initializers/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,21 @@ await api.redis.publish(payload)
args: args // [1,2,3]
}

await api.redis.publish(payload)

// we need to be sure that we build the response-handling promise before sending the request to Redis
// it is possible for another node to get and work the request before we resolve our write
// see https://github.com/actionhero/actionhero/issues/1244 for more information
let responsePromise
if (waitForResponse) {
let response = await new Promise((resolve, reject) => {
responsePromise = new Promise((resolve, reject) => {
let timer = setTimeout(() => reject(new Error('RPC Timeout')), api.config.general.rpcTimeout)
api.redis.rpcCallbacks[messageId] = {timer, resolve, reject}
})
}

return response
await api.redis.publish(payload)

if (waitForResponse) {
return Promise.resolve(responsePromise)
}
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 651f86b

Please sign in to comment.