@splunkdlt/managed-resource
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@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');
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @splunkdlt/managed-resource

Weekly Downloads

1

Version

1.1.0

License

Apache-2.0

Unpacked Size

140 kB

Total Files

17

Last publish

Collaborators

  • spuchbauer-splunk
  • tmio