File tree 3 files changed +44
-2
lines changed
3 files changed +44
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @devrev/meerkat-dbm" ,
3
- "version" : " 0.0.141 " ,
3
+ "version" : " 0.0.142 " ,
4
4
"dependencies" : {
5
5
"tslib" : " ^2.3.0" ,
6
6
"@duckdb/duckdb-wasm" : " ^1.28.0" ,
Original file line number Diff line number Diff line change @@ -160,7 +160,7 @@ describe('DBM', () => {
160
160
let db : AsyncDuckDB ;
161
161
let fileManager : FileManagerType ;
162
162
let dbm : DBM ;
163
- let instanceManager ;
163
+ let instanceManager : InstanceManager ;
164
164
165
165
beforeAll ( async ( ) => {
166
166
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -179,6 +179,9 @@ describe('DBM', () => {
179
179
onEvent : ( event ) => {
180
180
console . log ( event ) ;
181
181
} ,
182
+ options : {
183
+ shutdownInactiveTime : 100 ,
184
+ } ,
182
185
} ;
183
186
dbm = new DBM ( options ) ;
184
187
} ) ;
@@ -389,5 +392,29 @@ describe('DBM', () => {
389
392
*/
390
393
expect ( instanceManager . terminateDB ) . not . toBeCalled ( ) ;
391
394
} ) ;
395
+
396
+ it ( 'should not shutdown the db if the shutdown lock is true' , async ( ) => {
397
+ jest . spyOn ( instanceManager , 'terminateDB' ) ;
398
+
399
+ /**
400
+ * Set the shutdown lock to true
401
+ */
402
+ dbm . setShutdownLock ( true ) ;
403
+
404
+ /**
405
+ * Execute a query
406
+ */
407
+ await dbm . queryWithTableNames ( 'SELECT * FROM table1' , [ 'table1' ] ) ;
408
+
409
+ /**
410
+ * wait for 200ms
411
+ */
412
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 200 ) ) ;
413
+
414
+ /**
415
+ * Expect instanceManager.terminateDB to not be called
416
+ */
417
+ expect ( instanceManager . terminateDB ) . not . toBeCalled ( ) ;
418
+ } ) ;
392
419
} ) ;
393
420
} ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export class DBM {
17
17
private options : DBMConstructorOptions [ 'options' ] ;
18
18
private terminateDBTimeout : NodeJS . Timeout | null = null ;
19
19
private onDuckDBShutdown ?: ( ) => void ;
20
+ private shutdownLock = false ;
20
21
21
22
constructor ( {
22
23
fileManager,
@@ -35,6 +36,13 @@ export class DBM {
35
36
}
36
37
37
38
private async _shutdown ( ) {
39
+ /**
40
+ * If the shutdown lock is true, then don't shutdown the DB
41
+ */
42
+ if ( this . shutdownLock ) {
43
+ return ;
44
+ }
45
+
38
46
if ( this . connection ) {
39
47
await this . connection . close ( ) ;
40
48
this . connection = null ;
@@ -285,4 +293,11 @@ export class DBM {
285
293
*/
286
294
return connection . query ( query ) ;
287
295
}
296
+
297
+ /**
298
+ * Set the shutdown lock to prevent the DB from shutting down
299
+ */
300
+ public async setShutdownLock ( state : boolean ) {
301
+ this . shutdownLock = state ;
302
+ }
288
303
}
You can’t perform that action at this time.
0 commit comments