Comments (3)
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.io.waitFor('app') pour onStart demare app
// auto require de pm2 lightweight
// ipc pubsub
This is a simple draft, based on my intuition, @vmarchaud @wallet77 feedback welcome on this api design
from pm2-io-apm.
I think onSotp and onStart should exists by default and just execute the callback :
onStart/onStop (cb) {
cb()
}
In this case user can override only onStop for example.
from pm2-io-apm.
Done : #91
from pm2-io-apm.
Related Issues (20)
- Can't resolve 'async_hooks'
- NotifyFeature.getSafeError
- Outdated transitive dependency on continuation-local-storage leads to warnings
- Network metric results in MaxListenerExceededWarning errors HOT 1
- TypeError: Cannot convert undefined or null to object HOT 1
- PM2-io-apm always logs unhandledRejection and uncaughtException to error stream HOT 1
- no monitoring of worker_threads
- v5 doesn't work with v4 config for standalone
- Add method that can get process info
- io.meter is missing samples and timeframe Options in typescript HOT 2
- help - problems updating opencensus
- Memory leak due to res.once("finish")
- Importing @pm2/io breaks vscode debugging
- old dependency [email protected] HOT 3
- Does standalone mode work with free version
- Unmonitor does not persist on reboot HOT 1
- Latest version (5.0.1) committed not tagged/released HOT 9
- Update semver to 7.5.2 for security vulnerabilty HOT 3
- Security Vulnerability with semver version from opencensus
- Security vulnerability with loadash package version.
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 pm2-io-apm.