1.1.0 • Published 3 years ago
@splunkdlt/managed-resource v1.1.0
@splunkdlt/managed-resource
A set of helpers to perform an orderly shutdown of a collector process.
Example
The following example illustrates a tyipcal flow of a program using the managed-resource package:
const testResource = new TestResource();
const resources = [testResource];
try {
await Promise.race([runMainBackgroundJob(testResource), waitForSignal('SIGINT'), waitForSignal('SIGHUP')]);
} catch (e) {
console.error('Caught unexpected error', e);
} finally {
const cleanShutdown = await shutdownAll(resources, 60_0000);
console.log('Shutdown complete');
process.exit(cleanShutdown ? 0 : 1);
}
Resources passed to shutdownAll()
need to implement the ManagedResource
interface - which mainly requires to provide a shutdown()
method.
class TestResource implements ManagedResource {
// ...
async shutdown() {
console.log('Shutting down test resource');
await sleep(500);
console.log('Test resource shutdown complete');
}
}
1.1.0
3 years ago
1.0.2
3 years ago
1.0.1
4 years ago
1.0.0
4 years ago
1.0.0-alpha0.0
4 years ago
1.0.0-alpha0
4 years ago