UNPKG

2.4 kBTypeScriptView Raw
1import { ConfigParams } from "pip-services3-commons-node";
2import { IConfigurable } from "pip-services3-commons-node";
3import { IOpenable } from "pip-services3-commons-node";
4/**
5 * Random shutdown component that crashes the process
6 * using various methods.
7 *
8 * The component is usually used for testing, but brave developers
9 * can try to use it in production to randomly crash microservices.
10 * It follows the concept of "Chaos Monkey" popularized by Netflix.
11 *
12 * ### Configuration parameters ###
13 *
14 * - mode: null - crash by NullPointer excepiton, zero - crash by dividing by zero, excetion = crash by unhandled exception, exit - exit the process
15 * - min_timeout: minimum crash timeout in milliseconds (default: 5 mins)
16 * - max_timeout: maximum crash timeout in milliseconds (default: 15 minutes)
17 *
18 * ### Example ###
19 *
20 * let shutdown = new Shutdown();
21 * shutdown.configure(ConfigParams.fromTuples(
22 * "mode": "exception"
23 * ));
24 * shutdown.shutdown(); // Result: Bang!!! the process crashes
25 */
26export declare class Shutdown implements IConfigurable, IOpenable {
27 private _interval;
28 private _mode;
29 private _minTimeout;
30 private _maxTimeout;
31 /**
32 * Creates a new instance of the shutdown component.
33 */
34 constructor();
35 /**
36 * Configures component by passing configuration parameters.
37 *
38 * @param config configuration parameters to be set.
39 */
40 configure(config: ConfigParams): void;
41 /**
42 * Checks if the component is opened.
43 *
44 * @returns true if the component has been opened and false otherwise.
45 */
46 isOpen(): boolean;
47 /**
48 * Opens the component.
49 *
50 * @param correlationId (optional) transaction id to trace execution through call chain.
51 * @param callback callback function that receives error or null no errors occured.
52 */
53 open(correlationId: string, callback: (err: any) => void): void;
54 /**
55 * Closes component and frees used resources.
56 *
57 * @param correlationId (optional) transaction id to trace execution through call chain.
58 * @param callback callback function that receives error or null no errors occured.
59 */
60 close(correlationId: string, callback: (err: any) => void): void;
61 /**
62 * Crashes the process using the configured crash mode.
63 */
64 shutdown(): void;
65}