Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallbacks executions #90

Open
pauloballan opened this issue Aug 11, 2017 · 3 comments
Open

Fallbacks executions #90

pauloballan opened this issue Aug 11, 2017 · 3 comments

Comments

@pauloballan
Copy link

Hello!

I am implementing this circuit breaker for node.js and i noted something strange. In a normal flow for my, in this case, API call i always see that the fallback functions is being called, the service is working ok and the response is totally fine, but whenever i set a breakpoint in the fallback, it stops right there, even if the flow goes ok.
I am not sure why is it executing if there are not errors in the api call.

Thanks!

@awolden
Copy link
Owner

awolden commented Aug 11, 2017

Hey @pauloballan, that definitely shouldn't be happening. Can you give a code snippet of your implementation that I could look at?

Thanks,

-Alex

@pauloballan
Copy link
Author

Hi @awolden! Thanks for such a quick answer. I think i'm not getting it right the usage for the breaker. I am currently using callbacks in my project and the apicall is something like this:

`function apicall(params, callback) {

if (!params) {
    return callback({
        message: 'Invalid or missing params'
    });
}
client.get(opts, function(error, response){
  error = 'error';
  if (error){
    callback(error);
  }
  return callback(undefined, response && response.body);
});

};`

This function is forcing the error in order to see fallback working. And this is the brakes setting up:

const brake = new brakes(apicall, { statInterval: 2500, threshold: 0.2, circuitDuration: 15000, timeout: 1000 });

let apicallBrakes = function(params, callback){ brake.exec(params, callback); };

apicallBrakes is the one called as a client service.
With this code, the fallback is always being executed even is not throwing an error. I am not sure if this is recognized as an error or i am doing it wrong.
In this case it still calls the fallback (noted it using a console.log) but the apicall is not returning it.

Thanks!

@awolden
Copy link
Owner

awolden commented Aug 22, 2017

I don't see Hey @pauloballan thanks for sharing the code. Based on this I don't see where a fallback is being defined. Normally a fallback is defined via brakesInstance.fallback() or setting a fallback function in the initial options object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants