exframe-service
v1.6.2
Published
Service framework module for graceful shutdown/cleanup of resources
Downloads
8,136
Readme
exframe Service Module
Manage SIGTERM shutdown request
Features
- Built in creation of health checks for external GET endpoints
- Custom creaton of health checks where the built in health check doesn't meet requirements
- Automatically captures prometheus metrics for the running process
Use
const service = require('exframe-service');
Full Example
const service = require('exframe-service');
const logger = require('exframe-logger').create(process.env.LOGSENE_TOKEN || 'token');
const onSignalMQ = () => {
return new Promise((resolve, reject) => {
logger.debug('run mq cleanup code');
});
};
const onSignalRest = () => {
return new Promise((resolve, reject) => {
logger.debug('run rest cleanup code');
});
};
service.init({ logger, timeout: 10000 });
service.registerResource('db', { onSignal: onSignalDB, order: 'last' });
service.registerResource('mq', { onSignal: onSignalMQ });
service.registerResource('rest', { onSignal: onSignalRest });
};
Methods
init()
Syntax
service.init({ logger, timeout: 5000 })
Parameter Values
logger Required. logger object.
timeout Optional. wait time before exframe-service alerts registered node modules to shutdown (defaults to 10 seconds).
registerResource()
Syntax
service.registerResource('mq', { onSignal: onSignalMQ })
Parameter Values
name Required. name of registered service.
{ onSignal } Required. cleanup function that returns a promise.