-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathresourceRelease.js
More file actions
63 lines (47 loc) · 1.77 KB
/
resourceRelease.js
File metadata and controls
63 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*******************************************************************************
Highcharts Export Server
Copyright (c) 2016-2025, Highsoft
Licenced under the MIT licence.
Additionally a valid Highcharts license is required for use.
See LICENSE file in root for details.
*******************************************************************************/
/**
* @overview Handles graceful shutdown of the Highcharts Export Server, ensuring
* proper cleanup of resources such as browser, pages, servers, and timers.
*/
import { getBrowser } from './browser.js';
import { killPool } from './pool.js';
import { clearAllTimers } from './timer.js';
import { closeServers } from './server/server.js';
import { terminateClients } from './server/webSocket.js';
/**
* Performs cleanup operations to ensure a graceful shutdown of the process.
* This includes clearing all registered timeouts/intervals, closing active
* servers, terminating resources (pages) of the pool, pool itself, and closing
* the browser.
*
* @function shutdownCleanUp
*
* @param {number} [exitCode=0] - The exit code to use with `process.exit()`.
* The default value is `0`.
*/
export async function shutdownCleanUp(exitCode = 0) {
// Remove all attached event listeners from the browser
getBrowser().removeAllListeners('disconnected');
// Await freeing all resources
await Promise.allSettled([
// Clear all ongoing intervals
clearAllTimers(),
// Terminate all connected WebSocket clients
terminateClients(),
// Get available server instances (HTTP/HTTPS) and close them
closeServers(),
// Close an active pool along with its workers and the browser instance
killPool()
]);
// Exit process with a correct code
process.exit(exitCode);
}
export default {
shutdownCleanUp
};