Git Product home page Git Product logo

Comments (7)

tim-kos avatar tim-kos commented on August 10, 2024

Hey Michal,

sorry for the long delay here, but I was on vacation.

Could you please provide some example code?

Best,
Tim

from node-retry.

tim-kos avatar tim-kos commented on August 10, 2024

Hey @michaelkariv

Did you see my reply?

from node-retry.

jokesterfr avatar jokesterfr commented on August 10, 2024

@michaelkariv I think it's working the same way. Assuming you have a task object, which is an Event Listener emitting errors, and starting processing stuff after calling execute():

var operation = retry.operation();
var t = new Task();
t.on('error', function(err) {
 operation.retry(err);
});

operation.attempt(function (currentAttempt) {
    t.execute();
});

from node-retry.

tim-kos avatar tim-kos commented on August 10, 2024

Closing this. Feel free to re-open if our comments did not help.

from node-retry.

AlexZeitler avatar AlexZeitler commented on August 10, 2024

Based on @tim-kos answer here is a complete sample that checks for RabbitMQ + MongoDb connection using net and only continues code exection when both connections are available.

var net = require('net');
var retry = require('retry');
var async = require('async');


function tryConnect(HOST, PORT, cb) {
  var client = new net.Socket();
  var operation = retry.operation();
  var cbCalled = false;

  client.on('error', function(err) {
    console.log('error');
    operation.retry(err);
  });

  operation.attempt(function (currentAttempt) {
    client.connect(PORT, HOST, function(){
      console.log('CONNECTED TO: ' + HOST + ':' + PORT);
      if(!cbCalled) {      
        cb();
        cbCalled = true;
      }
    });
  });
}

async.parallel(
    [
    function(cb) {
      tryConnect('localhost', 5672, cb);
    },

    function(cb) {
      tryConnect('localhost', 27017, cb);
    }
    ], 
    function() { 
      console.log('both connected') 
    }
    )

from node-retry.

AlexZeitler avatar AlexZeitler commented on August 10, 2024

@tim-kos Given the example above: How would I call the callback with an error if retry options are { retries : 2, factor: 1 } and the call eventually fails in the end?

from node-retry.

AlexZeitler avatar AlexZeitler commented on August 10, 2024

Got it:

if(!operation.retry(err)) {
  cb(err, null)
}

from node-retry.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.