diff --git a/src/cluster/RedisDatastore.js b/src/cluster/RedisDatastore.js index 4cc9348..2ad6a28 100644 --- a/src/cluster/RedisDatastore.js +++ b/src/cluster/RedisDatastore.js @@ -48,7 +48,7 @@ class RedisDatastore { .then(() => { if (!this._disconnecting) { this.heartbeat = setInterval(() => { - return this.runScript("heartbeat", []).catch((e) => { + return this.runScript("heartbeat", [this.instance.queued()]).catch((e) => { if (!this._disconnecting) { this.instance.Events.trigger("error", e); } @@ -135,7 +135,12 @@ class RedisDatastore { e.message.match(/^(.*\s)?SETTINGS_KEY_NOT_FOUND$/) !== null ) { if (name === "heartbeat") { - return undefined; + if (this.instance.queued() > 0) { + await this.runScript("init", this.prepareInitSettings(false)); + await this.runScript("register_client", [this.instance.queued()]); + await this.instance._drainAll(); + } + return; } await this.runScript("init", this.prepareInitSettings(false)); return this.runScript(name, args); diff --git a/src/cluster/Scripts.js b/src/cluster/Scripts.js index 86eece5..d26d0d9 100644 --- a/src/cluster/Scripts.js +++ b/src/cluster/Scripts.js @@ -71,7 +71,7 @@ const templates = { heartbeat: { keys: exports.allKeys, headers: ["validate_keys", "validate_client", "process_tick"], - refresh_expiration: false, + refresh_expiration: true, code: lua["heartbeat.lua"], }, update_settings: { diff --git a/src/cluster/lua/heartbeat.lua b/src/cluster/lua/heartbeat.lua index 38aa599..e00c543 100644 --- a/src/cluster/lua/heartbeat.lua +++ b/src/cluster/lua/heartbeat.lua @@ -1 +1,8 @@ +local queued = tonumber(ARGV[num_static_argv + 1]) + +local groupTimeout = tonumber(redis.call('hget', settings_key, 'groupTimeout')) +if groupTimeout ~= nil and queued > 0 then + refresh_expiration(now, now, groupTimeout) +end + process_tick(now, true)