You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.js
+33-3Lines changed: 33 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,10 @@ class ServerlessDynamodbLocal {
88
88
convertEmptyValues: {
89
89
shortcut: "e",
90
90
usage: "Set to true if you would like the document client to convert empty values (0-length strings, binary buffers, and sets) to be converted to NULL types when persisting to DynamoDB.",
91
-
}
91
+
},
92
+
leaveOn: {
93
+
usage: 'Keep the process running until user sends kill command. This will kill the process the database is running once user sends terminate.'
94
+
}
92
95
}
93
96
},
94
97
noStart: {
@@ -225,11 +228,20 @@ class ServerlessDynamodbLocal {
225
228
if(!options.noStart){
226
229
dynamodbLocal.start(options);
227
230
}
231
+
228
232
returnBbPromise.resolve()
229
-
.then(()=>options.migrate&&this.migrateHandler())
230
-
.then(()=>options.seed&&this.seedHandler());
233
+
.then(()=>options.migrate&&this.migrateHandler())
234
+
.then(()=>options.seed&&this.seedHandler())
235
+
.then(()=>{
236
+
if(options.leaveOn){
237
+
returnBbPromise.resolve()
238
+
.then(()=>this._listenForTermination())
239
+
.then(()=>this.endHandler());
240
+
}
241
+
});
231
242
}
232
243
244
+
233
245
endHandler(){
234
246
if(!this.options.noStart){
235
247
this.serverlessLog("DynamoDB - stopping local database");
@@ -258,6 +270,24 @@ class ServerlessDynamodbLocal {
258
270
}).filter((n)=>n);
259
271
}
260
272
273
+
_listenForTermination(){
274
+
// SIGINT will be usually sent when user presses ctrl+c
275
+
constwaitForSigInt=newPromise(resolve=>{
276
+
process.on('SIGINT',()=>resolve('SIGINT'));
277
+
});
278
+
279
+
// SIGTERM is a default termination signal in many cases,
280
+
// for example when "killing" a subprocess spawned in node
0 commit comments