-
Notifications
You must be signed in to change notification settings - Fork 36
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
entrypoint: implement spec #60
Comments
const Entrypoint = require('@pm2/pm2.io').Entrypoint
class App extends Entrypoint {
// The .onStart is called by Entrypoint when initializing the app
onStart(cb) {
this.server = http.createServer((req, res) => {
res.send('Hello')
})
// The cb send process.send('ready') to PM2
// if we manage to retrieve the http instance we could bind it to
// https://github.com/hunterloftis/stoppable
this.server.listen(8000, cb)
}
// The .onStop is called when the app will exit (exception, rejection, sigint, sigstop...)
onStop(cb) {
}
// Just a method to cleanly list metrics
metrics() {
this.meter('stuff-metrics', () => {
return 42
})
}
// To cleanly list diagnostics
diagnostics() {
this.on('getEnv', (cb) => {
cb(null, process.env)
})
}
}
module.exports = new Entrypoint class Entrypoint {
constructor () {
this.io = io.init(this.conf())
this.onStart(err => () {
this.metrics()
this.diagnostics()
this.io.onExit((err) => {
this.onStop(err, () => {
this.io.destroy()
})
})
process.send('ready')
})
},
onStart () {
throw new Error('Entrypoint onStart() not specified')
},
onStop () {
throw new Error('Entrypoint onStop() not specified')
},
conf () {
return { defaultConf }
}
} // wait_ready? listen_timeout? kill_timeout? This is a simple draft, based on my intuition, @vmarchaud @wallet77 feedback welcome on this api design |
I think onSotp and onStart should exists by default and just execute the callback : In this case user can override only onStop for example. |
Done : #91 |
No description provided.
The text was updated successfully, but these errors were encountered: