Skip to content

Commit 8f7b56e

Browse files
add console messages for shutting down the database
1 parent 1ff6464 commit 8f7b56e

File tree

5 files changed

+48
-11
lines changed

5 files changed

+48
-11
lines changed

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,28 +213,38 @@ The internal queries that are ran before the queries in ```initSQLString``` are
213213
***
214214
### :warning: Internal Options :warning:
215215

216-
The following options are only meant for internal debugging use. Their behaviour may change or they may get removed between major/minor/patch versions and they are not to be considered stable. The options below will not follow Semantic Versioning so it is advised to not use them.
216+
The following options are only meant for internal use (such as CI or the internals for running this package via the CLI). Their behaviour may change or they may get removed between major/minor/patch versions and they are not to be considered stable. The options below will not follow Semantic Versioning so it is advised to not use them.
217217

218218
- `_DO_NOT_USE_deleteDBAfterStopped: boolean`
219219

220-
Required: No
221-
222220
Default: true
223221

224222
Description: Changes whether or not the database will be deleted after it has been stopped. If set to `true`, the database WILL be deleted after it has been stopped.
225223

226224
- `_DO_NOT_USE_dbPath: string`
227225

228-
Required: No
229-
230226
Default: `TMPDIR/mysqlmsn/dbs/UUID` (replacing TMPDIR with the OS temp directory and UUID with a UUIDv4 without seperating dashes).
231227

232228
Description: The folder to store database-related data in
233229

234230
- `_DO_NOT_USE_binaryDirectoryPath: string`
235231

236-
Required: No
237-
238232
Default: `TMPDIR/mysqlmsn/binaries` (replacing TMPDIR with the OS temp directory)
239233

240234
Description: The folder to store the MySQL binaries when they are downloaded from the CDN.
235+
236+
- `_DO_NOT_USE_beforeSignalCleanupMessage: string`
237+
238+
Required: No
239+
240+
Default: undefined
241+
242+
Description: The message to get displayed in the console before the cleanup that happens when the Node.js process is stopped without the ```stop()``` method being called first.
243+
244+
- `_DO_NOT_USE_afterSignalCleanupMessage: string`
245+
246+
Required: No
247+
248+
Default: undefined
249+
250+
Description: The message to get displayed in the console after the cleanup that happens when the Node.js process is stopped without the ```stop()``` method being called first.

src/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { OPTION_TYPE_CHECKS } from "./constants";
44

55
async function main() {
66
const definedOptions = process.argv.filter((option) => option.startsWith('--'))
7-
const options = {}
7+
const options = {
8+
_DO_NOT_USE_beforeSignalCleanupMessage: 'Shutting down the epehemeral MySQL database and cleaning all related files...',
9+
_DO_NOT_USE_afterSignalCleanupMessage: 'Shutdown and cleanup is complete.'
10+
}
811
for (const opt of definedOptions) {
912
const index = process.argv.indexOf(opt)
1013
const optionValue = process.argv[index + 1]

src/constants.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const DEFAULT_OPTIONS_GENERATOR: () => InternalServerOptions = () => ({
2323
_DO_NOT_USE_deleteDBAfterStopped: true,
2424
//mysqlmsn = MySQL Memory Server Node.js
2525
_DO_NOT_USE_dbPath: normalizePath(`${tmpdir()}/mysqlmsn/dbs/${randomUUID().replace(/-/g, '')}`),
26-
_DO_NOT_USE_binaryDirectoryPath: `${tmpdir()}/mysqlmsn/binaries`
26+
_DO_NOT_USE_binaryDirectoryPath: `${tmpdir()}/mysqlmsn/binaries`,
27+
_DO_NOT_USE_beforeSignalCleanupMessage: '',
28+
_DO_NOT_USE_afterSignalCleanupMessage: ''
2729
});
2830

2931
export const DEFAULT_OPTIONS_KEYS = Object.freeze(Object.keys(DEFAULT_OPTIONS_GENERATOR()))
@@ -34,7 +36,7 @@ export const LOG_LEVELS = {
3436
'ERROR': 2
3537
} as const;
3638

37-
export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath'] as const;
39+
export const INTERNAL_OPTIONS = ['_DO_NOT_USE_deleteDBAfterStopped', '_DO_NOT_USE_dbPath', '_DO_NOT_USE_binaryDirectoryPath', '_DO_NOT_USE_beforeSignalCleanup', '_DO_NOT_USE_afterSignalCleanup'] as const;
3840

3941
export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
4042
version: {
@@ -116,5 +118,15 @@ export const OPTION_TYPE_CHECKS: OptionTypeChecks = {
116118
check: (opt: any) => opt === undefined || typeof opt === 'string',
117119
errorMessage: 'Option _DO_NOT_USE_binaryDirectoryPath must be either undefined or a string.',
118120
definedType: 'string'
121+
},
122+
_DO_NOT_USE_beforeSignalCleanupMessage: {
123+
check: (opt: any) => opt === undefined || typeof opt === 'string',
124+
errorMessage: 'Option _DO_NOT_USE_beforeSignalCleanup must be either undefined or a string.',
125+
definedType: 'string'
126+
},
127+
_DO_NOT_USE_afterSignalCleanupMessage: {
128+
check: (opt: any) => opt === undefined || typeof opt === 'string',
129+
errorMessage: 'Option _DO_NOT_USE_afterSignalCleanup must be either undefined or a string.',
130+
definedType: 'string'
119131
}
120132
} as const;

src/libraries/Executor.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ class Executor {
421421

422422
async startMySQL(options: InternalServerOptions, binaryFilepath: string): Promise<MySQLDB> {
423423
this.removeExitHandler = onExit(() => {
424+
if (options._DO_NOT_USE_beforeSignalCleanupMessage) {
425+
console.log(options._DO_NOT_USE_beforeSignalCleanupMessage)
426+
}
427+
424428
this.DBDestroySignal.abort()
425429

426430
if (options._DO_NOT_USE_deleteDBAfterStopped) {
@@ -439,6 +443,10 @@ class Executor {
439443
this.logger.error('An error occurred while deleting database binary:', e)
440444
}
441445
}
446+
447+
if (options._DO_NOT_USE_afterSignalCleanupMessage) {
448+
console.log(options._DO_NOT_USE_afterSignalCleanupMessage)
449+
}
442450
})
443451

444452
let retries = 0;

types/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ export type ServerOptions = {
1818
initSQLString?: string | undefined
1919
_DO_NOT_USE_deleteDBAfterStopped?: boolean | undefined,
2020
_DO_NOT_USE_dbPath?: string | undefined,
21-
_DO_NOT_USE_binaryDirectoryPath?: string | undefined
21+
_DO_NOT_USE_binaryDirectoryPath?: string | undefined,
22+
_DO_NOT_USE_beforeSignalCleanupMessage?: string | undefined,
23+
_DO_NOT_USE_afterSignalCleanupMessage?: string | undefined
2224
}
2325

2426
export type InternalServerOptions = {
@@ -38,6 +40,8 @@ export type InternalServerOptions = {
3840
_DO_NOT_USE_deleteDBAfterStopped: boolean,
3941
_DO_NOT_USE_dbPath: string,
4042
_DO_NOT_USE_binaryDirectoryPath: string,
43+
_DO_NOT_USE_beforeSignalCleanupMessage: string,
44+
_DO_NOT_USE_afterSignalCleanupMessage: string
4145
}
4246

4347
export type ExecutorOptions = {

0 commit comments

Comments
 (0)