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

Get the health status without using a HTTP request #83

Closed
BrunnerLivio opened this issue Oct 1, 2018 · 4 comments
Closed

Get the health status without using a HTTP request #83

BrunnerLivio opened this issue Oct 1, 2018 · 4 comments

Comments

@BrunnerLivio
Copy link
Contributor

Issue

I would like to read out the current health status, without having to create a HTTP request.
Therefore the health status should be readable programmatically using the public Terminus API.

Something like this:

const { getHealthStatus } = require('@godaddy/terminus');

// Returns { status: 'ok' | 'error', info: {...} }
getHealthStatus('/health');

Implementation

Looking through your code, I realized the core (terminus.js) would have to get restructured if done correctly.

When I tried to refactor the method decorateWithHealthCheck in terminus.js which contains the desired functionality, I realized everything is handled over parameters. My refactored function would look like the following:

function getHealthStatus(url, state, options) {
  const { healthChecks, logger } = options;
  if (state.isShuttingDown) {
    return sendFailure(res)
  }
  healthChecks[url]()
    .then((info) => {
      sendSuccess(res, info)
    })
    .catch((error) => {
      logger('healthcheck failed', error)
      sendFailure(res, error.causes)
    })
}

The problem is, a user should not pass state nor options as a parameter. Thus it is still required for the functionality of getHealthStatus. A way to solve this problem, is to use a class instance for each createTerminus() call, which then can handle state or options as a property.

@gergelyke
Copy link
Collaborator

Hi @BrunnerLivio - any chance you can work on a PR to address this? If not, I can take it on sometimes next week.

@BrunnerLivio
Copy link
Contributor Author

I also do not know if I have time for this either, but try to look into it.

I think I have to break the public API (again 😅 ) in order to achieve this.

@gergelyke
Copy link
Collaborator

No worries - that's why we have semver :)

@gergelyke
Copy link
Collaborator

Closing this as per #87

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