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

Passing function parameters to events #324

Closed
mykevinjung opened this issue Jun 7, 2019 · 4 comments · Fixed by #326
Closed

Passing function parameters to events #324

mykevinjung opened this issue Jun 7, 2019 · 4 comments · Fixed by #326

Comments

@mykevinjung
Copy link

This is more of a question than an issue. I like to use the parameters that were passed in the action function and do something in the event. For instance, let's say x and y are passed in asyncFunctionThatCouldFail function and I like to print out the x and y on timeout event. How can I do that?

const circuitBreaker = require('opossum');

function asyncFunctionThatCouldFail (x, y) {
  return new Promise((resolve, reject) => {
    // Do something, maybe on the network or a disk
  });
}

const options = {
  timeout: 3000, // If our function takes longer than 3 seconds, trigger a failure
  errorThresholdPercentage: 50, // When 50% of requests fail, trip the circuit
  resetTimeout: 30000 // After 30 seconds, try again.
};
const breaker = circuitBreaker(asyncFunctionThatCouldFail, options);

breaker.fire(params);
circuit.on('timeout',
  () => console.log(`x equal ${x} and y equal ${y}`)); // the parameters of asyncFunctionThatCouldFail
@lholmquist
Copy link
Member

It doesn't look like that is currently possible. The timeout event is only emitted with the error and the latency value.

@lance what do you think about adding the original function arguments to the timeout event when it is emitted?

I can send a PR

@lance
Copy link
Member

lance commented Jun 10, 2019

@lholmquist yes - that sounds good. I wonder if it should necessarily be limited to timeout. The open and failure events might benefit from this as well.

@lholmquist
Copy link
Member

agreed, i'll added them too, to see how it feels.

@mykevinjung
Copy link
Author

Thanks for the response. It would be great to help diagnose the issue if we can know the inputs especially for those events like timeout and failure.

lholmquist added a commit to lholmquist/opossum that referenced this issue Jun 10, 2019
lholmquist added a commit to lholmquist/opossum that referenced this issue Jun 10, 2019
lholmquist added a commit to lholmquist/opossum that referenced this issue Jun 10, 2019
lholmquist added a commit to lholmquist/opossum that referenced this issue Jun 10, 2019
lance pushed a commit that referenced this issue Jun 11, 2019
…nts (#326)

* feat: add the original function parameters to the list of arguments emitted in a timeout event.
* feat: add the original function parameters to the list of arguments emitted in a failure event.
* chore: remove whitespace, editor plugin

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

Successfully merging a pull request may close this issue.

3 participants