How to use the backoff.exponential 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 layr-team / Layr / audit / client / node.js View on Github external
serverConnection.on('data', (data) => {
    let receivedData = JSON.parse(data);

    if (receivedData.messageType === "CLI_UPLOAD_FILE") {
      let filePath = receivedData.filePath;

      batnode3.uploadFile(filePath);
    } else if (receivedData.messageType === "CLI_DOWNLOAD_FILE") {
      let filePath = receivedData.filePath;

      batnode3.retrieveFile(filePath);
    } else if (receivedData.messageType === "CLI_AUDIT_FILE") {
      let filePath = receivedData.filePath;
      let fibonacciBackoff = backoff.exponential({
          randomisationFactor: 0,
          initialDelay: 20,
          maxDelay: 2000
      });
      console.log("received path: ", filePath);
      batnode3.auditFile(filePath);

      // post audit cleanup
      serverConnection.on('close', () => {
        batnode3._audit.ready = false;
        batnode3._audit.data = null;
        batnode3._audit.passed = false;
      });

      fibonacciBackoff.failAfter(10);
github grover / homebridge-dacp / src / DacpAccessory.js View on Github external
this.api = api;
    Characteristic = this.api.hap.Characteristic;
    Service = this.api.hap.Service;

    this.log = log;
    this.name = config.name;
    this.serviceName = config.serviceName;

    this.config = config;

    this._isAnnounced = false;
    this._isReachable = false;
    this._playStatusUpdateListeners = [];

    // Maximum backoff is 15mins when a device/program is visible
    this._backoff = backoff.exponential({
      initialDelay: 100,
      maxDelay: 900000
    }).on('backoff', (number, delay) => this._onBackoffStarted(delay))
      .on('ready', () => this._connectToDacpDevice());

    this._dacpClient = new DacpClient(log)
      .on('failed', e => this._onDacpFailure(e));

    this._services = this.createServices(this.api.hap);
  }
github nylas / nylas-nodejs / src / models / delta.js View on Github external
constructor(createRequest, connection, cursor, params = {}) {
    super(createRequest, connection, cursor, params);
    this.createRequest = createRequest;
    this.connection = connection;
    this.cursor = cursor;
    this.params = params;
    if (!(this.connection instanceof require('../nylas-connection'))) {
      throw new Error('Connection object not provided');
    }
    this.restartBackoff = backoff.exponential({
      randomisationFactor: 0.5,
      initialDelay: 250,
      maxDelay: 30000,
      factor: 4,
    });
    this.restartBackoff.failAfter(DeltaStream.MAX_RESTART_RETRIES);
    this.restartBackoff
      .on('backoff', this._restartConnection.bind(this))
      .on('fail', () => {
        return this.emit(
          'error',
          `Nylas DeltaStream failed to reconnect after 
          ${DeltaStream.MAX_RESTART_RETRIES}
          retries.`
        );
      });
github pgte / level-jobs / server.js View on Github external
function handleRunError(err) {
      var errorBackoff = backoff.exponential(q._options.backoff);
      errorBackoff.failAfter(q._options.maxRetries);

      errorBackoff.on('ready', function() {
        q.emit('retry', err);
        run(q, key, JSON.parse(work), ranAgain);
      });

      errorBackoff.once('fail', function() {
        q.emit('error', new Error('max retries reached'));
      });

      function ranAgain(err) {
        if (err) errorBackoff.backoff();
        else ran();
      }
github layr-team / Layr / kad-bat-plugin / batnode.js View on Github external
async asyncCallAssembleShards(completeFileSize, fileName, distinctShards) {
    let exponentialBackoff = backoff.exponential({
        randomisationFactor: 0,
        initialDelay: 10,
        maxDelay: 1000
    });

    const result = await this.sumShardsWhenFinish(completeFileSize, distinctShards, exponentialBackoff);

    if (result === completeFileSize) {
      fileUtils.assembleShards(fileName, distinctShards);
    } else {
      new Error(console.log("Error occurred, file size does not match manifest's record."));
    }
  }
github node-red / node-red-web-nodes / google / google.js View on Github external
function createExponentialBackoff() {
        var exponentialBackoff = backoff.exponential({
            initialDelay: 100,
            maxDelay: 73000,
            factor: 9
        });
        exponentialBackoff.failAfter(4);
        return exponentialBackoff;
    }
github rokucommunity / vscode-brightscript-language / src / ActiveDeviceManager.ts View on Github external
private findDevices() {
        this.exponentialBackoff = backoff.exponential({
            randomisationFactor: 0,
            initialDelay: 1000,
            maxDelay: 30000
        });

        this.exponentialBackoff.on('ready', (eventNumber, delay) => {
            this.discoverAll(delay);
            this.exponentialBackoff.backoff();
        });

        this.exponentialBackoff.backoff();
        this.isRunning = true;
    }

backoff

Fibonacci and exponential backoffs.

MIT
Latest version published 9 years ago

Package Health Score

65 / 100
Full package analysis