Comments (3)
as per doc using beforeShutdown hook i can wait but i don't understand the timeout option at this point
const http = require('http');
const { createTerminus } = require('@godaddy/terminus');
function onSignal () {
console.log('server is starting cleanup');
}
function beforeShutdown () {
console.log('waiting');
return new Promise(resolve => {
setTimeout(resolve, 30000)
})
}
function onShutdown () {
console.log('cleanup finished, server is shutting down');
}
const server = http.createServer((request, response) => {
response.end(
`<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>`
);
})
const options = {
timeout: 30000,
onSignal: onSignal,
onShutdown: onShutdown,
beforeShutdown: beforeShutdown
};
createTerminus(server,options);
server.listen(8080);
from terminus.
I forked the repo to do a little experimentation with the timeout handling. afaik timeout does work, I don't think your test is exercising the feature correctly b/c you aren't creating any connections before stopping the server. It might be helpful if there was a test case to verify timeout is respected. You can see my findings here:
MichaelSitter#1
from terminus.
thank you @MichaelSitter I confirm that with requests flowing the following snippet works:
const http = require('http');
const { createTerminus } = require('@godaddy/terminus');
function onSignal () {
console.log('server is starting cleanup');
}
function beforeShutdown () {
console.log('waiting for k8s environment to completely drain this service');
return new Promise(resolve => {
setTimeout(resolve, 10000)
})
}
function onShutdown () {
console.log('cleanup finished, server is shutting down');
}
const server = http.createServer(
(req, res) => {
setTimeout(() => {
res.end('hello')
}, 5000)
})
const options = {
timeout: 10000,
onSignal: onSignal,
onShutdown: onShutdown,
beforeShutdown: beforeShutdown
};
createTerminus(server,options);
server.listen(8080);
from terminus.
Related Issues (20)
- Question: Why using process.kill instead of process.exit? HOT 4
- "example" package flagged for CVE-2019-17426 HOT 3
- Request to release 4.4.2 HOT 5
- Last release was May 5. HOT 1
- Upgrade mongoose package version in example directory HOT 2
- use of setHandler flag ,initializing with false then setting it to true in lib/terminus line 63 HOT 1
- How to attach tracer to shutdown in Express app? HOT 2
- Custom status code on healthcheck HOT 2
- Typings are failing HOT 1
- How can I control the termination? HOT 4
- Expose a current state to a health check HOT 6
- Option to configure top-level successful response's value HOT 2
- Configurable health response options via middleware? HOT 4
- Missing typing information for headers HOT 3
- non graceful shutdown in kubernetes and docker with alpine HOT 2
- Mongoose example version breaks security scans, throws false positive HOT 1
- How to use this library with websocket library ws?
- Can Terminus be used as an ExpressJS middleware? HOT 1
- Adding signal type to onSignal function HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminus.