Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "serviced", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Microservice dependency readiness probe", | ||
@@ -5,0 +5,0 @@ "main": "serviced.js", |
@@ -12,3 +12,2 @@ # Serviced | ||
I use this to ensure I don't start certain processes (for example, our API server) before the backing services (db, message broker and kubernetes api) are up, running and reachable. Internally `serviced` uses `backoff` and `request` for http calls and retries. | ||
@@ -24,25 +23,60 @@ ## Usage | ||
const service1 = { | ||
name: 'db', | ||
url: 'http://db', | ||
json: true, | ||
maxDelay: 1000, | ||
numberOfBackoffs: 10, | ||
// Test that a single service returns status code 200. | ||
new Serviced('http://exmample.com').then(() => { | ||
// Your service is online and returns status code 200. | ||
}); | ||
// Test that multiple services returns status code 200. | ||
new Serviced('http://svc-a.com', 'http://svc-b.com').then(() => { | ||
// Both services are online and return status codes 200. | ||
}); | ||
// Test the response body from a service request with a test function. | ||
new Serviced({ | ||
url: 'http://svc-a.com', | ||
test(body) { | ||
return body.foo === true; | ||
}, | ||
}; | ||
}).then(() => { | ||
// Service is online and response passes supplied test. | ||
}); | ||
const service2 = { | ||
name: 'kubernetes', | ||
url: 'http://localhost:8080', | ||
// Test the response body from multiple service requests with test functions. | ||
new Serviced({ | ||
url: 'http://svc-a.com', | ||
test(body) { | ||
return body.foo === true; | ||
}, | ||
}, { | ||
url: 'http://svc-b.com', | ||
test(body) { | ||
return body.bar === true; | ||
}, | ||
}; | ||
}).then(() => { | ||
// Services are online and responses pass supplied tests. | ||
}); | ||
const services = new Serviced(service1, service2); | ||
// Pass additional options to underlying request and retry modules. | ||
new Serviced({ | ||
url: 'http://svc-a.com', | ||
request: { // pass options to request | ||
auth: { | ||
user: 'username', | ||
pass: 'password', | ||
} | ||
}, | ||
retry: { // pass options to retry | ||
retries: 2, | ||
maxTimeout: 2000, | ||
}, | ||
test(body) { | ||
return body.foo === true; | ||
}, | ||
}).then(() => { | ||
// Service is online and response passes supplied test. | ||
}); | ||
``` | ||
services.then(() => { | ||
// Your services have responded and are ready. | ||
}); | ||
## Change log | ||
* 2.0.0 Breaking changes from 1.x. I switched to `retry` over `backoff` primarily because of how it handles errors but also for simplicity. |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
8920
81
1