fix: refs #5483 run DB config fixes

This commit is contained in:
Juan Ferrer 2024-01-05 10:28:05 +01:00
parent 5f2e2c3933
commit d23a5bee05
3 changed files with 14 additions and 5 deletions

View File

@ -1,13 +1,11 @@
const EventEmitter = require('node:events');
/** /**
* Base class for Myt commands. * Base class for Myt commands.
*/ */
module.exports = class MytCommand extends EventEmitter { module.exports = class MytCommand{
constructor(myt, opts) { constructor(myt, opts) {
super();
this.myt = myt; this.myt = myt;
this.opts = opts; this.opts = opts;
this.handlers = {};
} }
async cli(myt, opts) { async cli(myt, opts) {
@ -27,4 +25,13 @@ module.exports = class MytCommand extends EventEmitter {
async run(myt, opts) { async run(myt, opts) {
throw new Error('run command not defined'); throw new Error('run command not defined');
} }
on(event, handler) {
this.handlers[event] = handler;
}
emit(event, ...args) {
const handler = this.handlers[event];
if (handler) handler (...args);
}
} }

View File

@ -87,7 +87,7 @@ class Run extends Command {
this.emit('runningContainer'); this.emit('runningContainer');
const isRandom = opts.random; const isRandom = opts.random;
const dbConfig = Object.assign({}, opts.dbConfig); const dbConfig = opts.dbConfig;
let runOptions; let runOptions;
@ -193,6 +193,7 @@ class Run extends Command {
} }
} }
await conn.end();
return server; return server;
} }
} }

1
myt.js
View File

@ -165,6 +165,7 @@ class Myt {
} }
async run(Command, opts) { async run(Command, opts) {
if (!opts) opts = this.opts;
const command = new Command(this, opts); const command = new Command(this, opts);
if (this.cliMode) if (this.cliMode)
return await command.cli(this, opts); return await command.cli(this, opts);