Browse Source

fix: Abort redis retries only for esbuild

version-14
Faris Ansari 4 years ago
parent
commit
807070282c
3 changed files with 27 additions and 14 deletions
  1. +2
    -2
      esbuild/esbuild.js
  2. +16
    -1
      esbuild/utils.js
  3. +9
    -11
      node_utils.js

+ 2
- 2
esbuild/esbuild.js View File

@@ -21,9 +21,9 @@ let {
log,
log_warn,
log_error,
bench_path
bench_path,
get_redis_subscriber
} = require("./utils");
let { get_redis_subscriber } = require("../node_utils");

let argv = yargs
.usage("Usage: node esbuild [options]")


+ 16
- 1
esbuild/utils.js View File

@@ -110,6 +110,20 @@ function log(...args) {
console.log(...args); // eslint-disable-line no-console
}

function get_redis_subscriber(kind) {
// get redis subscriber that aborts after 50 connection attempts
let { get_redis_subscriber: get_redis } = require("../node_utils");
return get_redis(kind, {
retry_strategy: function(options) {
// abort after 50 connection attempts
if (options.attempt > 50) {
return undefined;
}
return Math.min(options.attempt * 100, 2000);
}
});
}

module.exports = {
app_list,
bench_path,
@@ -126,5 +140,6 @@ module.exports = {
get_cli_arg,
log,
log_warn,
log_error
log_error,
get_redis_subscriber
};

+ 9
- 11
node_utils.js View File

@@ -38,19 +38,17 @@ function get_conf() {
return conf;
}

function get_redis_subscriber(kind="redis_socketio") {
function get_redis_subscriber(kind="redis_socketio", options=null) {
const conf = get_conf();
const host = conf[kind] || conf.redis_async_broker_port;
return redis.createClient({
host,
retry_strategy: function(options) {
// abort after 5 connection attempts
if (options.attempt > 5) {
return undefined;
}
return Math.min(options.attempt * 100, 2000);
},
});

if (options) {
return redis.createClient({
host,
...options
});
}
return redis.createClient(host);
}

module.exports = {


Loading…
Cancel
Save