How to use the backoff.ExponentialStrategy function in backoff

To help you get started, we’ve selected a few backoff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-opcua / node-opcua / packages / node-opcua-secure-channel / source / client / client_secure_channel_layer.ts View on Github external
this.__call.on("backoff", onBackoffFunc);

        this.__call.on("abort", () => {
            debugLog(chalk.bgWhite.cyan(` abort #   after ${this.__call.getNumRetries()} retries.`));
            // Do something when backoff starts, e.g. show to the
            // user the delay before next reconnection attempt.
            /**
             * @event backoff
             */
            this.emit("abort");
            setImmediate(() => {
                this._backoff_completion(undefined, new Error("Connection abandoned"), transport, callback);
            });
        });

        this.__call.setStrategy(new backoff.ExponentialStrategy(this.connectionStrategy));
        this.__call.start();
    }
github node-opcua / node-opcua / packages / node-opcua-secure-channel / src / client / client_secure_channel_layer.js View on Github external
self.__call.on("abort", function () {
            debugLog(" abort #".bgWhite.cyan, " after ", self.__call.getNumRetries(), " retries");
            // Do something when backoff starts, e.g. show to the
            // user the delay before next reconnection attempt.
            /**
             * @event backoff
             */
            self.emit("abort");

            setImmediate(function () {
                _backoff_completion(null, new Error("Connection abandoned"));
            });

        });

        self.__call.setStrategy(new backoff.ExponentialStrategy(self.connectionStrategy));
        self.__call.start();

    };
github frandallfarmer / neohabitat / db / populateModels.js View on Github external
templatedJSON = templateHabitatObject(data);
            var habitatObject = JSON.parse(templatedJSON);

            // Figures out how we're going to write the object to Mongo.
            var updateWithRetries = null;
            if (habitatObject instanceof Array) {
              updateWithRetries = backoff.call(
                eupdateArray, db, habitatObject, habitatObjectUpdateFinished);
            } else {
              updateWithRetries = backoff.call(
                eupdateOne, db, habitatObject, habitatObjectUpdateFinished);
            }

            // Sets retry parameters.
            updateWithRetries.retryIf(function(err) { return err != null; });
            updateWithRetries.setStrategy(new backoff.ExponentialStrategy());
            updateWithRetries.failAfter(10);

            // Starts the Habitat object update process.
            updatesInFlight++;
            updateWithRetries.start();
          } catch (e) {
            console.error('Failed to parse file:', objectPath);
            console.error(templatedJSON);
            return console.error(e);
          }
        });
      }
github mcavage / node-fast / lib / client.js View on Github external
var max = Infinity;
    var opts = this._options;
    var retry = backoff.call(this._createSocket.bind(this), {},
    function (err, conn) {
        // Starting with backoff 2.5.0, the backoff callback is called when the
        // backoff instance is aborted. In this case, the _onConnection callback
        // should not be called, since its purpose is to handle the result of
        // the bind call that is being backed off, not events in the backoff
        // process itself.
        if (!retry.isAborted()) {
            self._onConnection(err, conn);
        }
    });

    retry.on('backoff', this.emit.bind(this, 'connectAttempt'));
    retry.setStrategy(new backoff.ExponentialStrategy({
        initialDelay: opts.retry.minTimeout || 1000,
        maxDelay: opts.retry.maxTimeout || Infinity
    }));

    if (typeof (opts.retry.retries) === 'number')
        max = opts.retry.retries;

    retry.failAfter(max);

    this._fast_retry = retry;
    this._fast_retry.start();
};
github whois-api-llc / node-email-verifier / index.js View on Github external
return cb(new Error(json.ErrorMessage.msg));
        }

        if (json && !json.emailAddress) {
          console.log(json);
          return cb(new Error("Oops! It looks like whoisxmlapi.com is having issues. Sorry!"));
        }

        cb(null, json);
      } catch(err) {
        cb(err);
      }
    });

    call.retryIf(err => { return err });
    call.setStrategy(new backoff.ExponentialStrategy);
    call.failAfter(this.opts.retries || RETRIES);
    call.start();
  }
}
github ayakashi-io / ayakashi / src / prelude / actions / retry.ts View on Github external
ayakashiInstance.retry = async function(task, retries = 10) {
        if (!task || typeof task !== "function") {
            throw new Error(" requires a function to run");
        }
        if (retries <= 0) {
            //tslint:disable no-parameter-reassignment
            retries = 10;
            //tslint:enable
        }
        let retried = 0;
        const strategy = new ExponentialStrategy({
            randomisationFactor: 0.5,
            initialDelay: 500,
            maxDelay: 5000,
            factor: 2
        });
        const errForStack = new Error();
        Error.captureStackTrace(errForStack, ayakashiInstance.retry);
        let filename = "";
        if (errForStack && errForStack.stack) {
            const stackMatch = errForStack.stack.match(/\/([\/\w-_\.]+\.js):(\d*):(\d*)/);
            if (stackMatch && stackMatch[0]) {
                filename = stackMatch[0].split(sep).pop() || "";
            }
        }
        return new Promise(function(resolve, reject) {
            asyncRetry({
github restify / node-restify / lib / clients / http_client.js View on Github external
assert.object(opts, 'options');
    assert.func(cb, 'callback');

    cb = once(cb);

    if (opts.retry === false) {
        rawRequest(opts, cb);
        return;
    }

    var call;
    var retry = cloneRetryOptions(opts.retry);

    opts._keep_alive = this._keep_alive;
    call = backoff.call(rawRequest, opts, cb);
    call.setStrategy(new backoff.ExponentialStrategy({
        initialDelay: retry.minTimeout,
        maxDelay: retry.maxTimeout
    }));
    call.failAfter(retry.retries);
    call.on('backoff', this.emit.bind(this, 'attempt'));

    call.start();
};
github joyent / smartos-live / src / img / node_modules / sdc-clients / node_modules / restify / lib / clients / http_client.js View on Github external
HttpClient.prototype.request = function request(opts, cb) {
        assert.object(opts, 'options');
        assert.func(cb, 'callback');

        cb = once(cb);

        var call;
        var retry = cloneRetryOptions(opts.retry);

        opts._keep_alive = this._keep_alive;
        call = backoff.call(rawRequest, opts, cb);
        call.setStrategy(new backoff.ExponentialStrategy({
                initialDelay: retry.minTimeout,
                maxDelay: retry.maxTimeout
        }));
        call.failAfter(retry.retries);
        call.on('backoff', this.emit.bind(this, 'attempt'));

        call.start();
};

backoff

Fibonacci and exponential backoffs.

MIT
Latest version published 9 years ago

Package Health Score

65 / 100
Full package analysis