new winston.transports.Console({ timestamp: () => dayjs().format('HH:mm:ss'), formatter: options => { winston.config.colorize(elementColor, _.padEnd(element.toLowerCase(), fcw)), winston.config.colorize('timestamp', options.timestamp()), winston.config.colorize(options.level, options.level.toUpperCase()), '==>', util.format(options.message), transports.push(new winston.transports.File({ name: 'error-file', label: logName, filename: path.join(logDir, `${logName}-error.log`), })); transports.push(new winston.transports.File({ name: 'log-file', label: logName,
listen() { return new Promise((resolve, reject) => { this._server = this._app.listen(this._port, (err) => { if (err) { return reject(err); } winston.info('[TestServer] listen at port %d', this._port); resolve(); }); }); }
waitForAliveInstances(count) { winston.debug('[Manager] waitForAliveInstances: count=%d', count); if (this._aliveInstances.length === count) { return Promise.resolve(); } else { return Promise .delay(2000) .then(() => this.waitForAliveInstances(count)); } }
//////////// function handleError(err) { winston.error(err); this.emit('end'); }
// Restart instance if stopped self.on('status:updated', (newstatus) => { // Restart if stopped if (newstatus === InstanceModel.STOPPED) { self._provider.startInstance(self._model) .catch((err) => { winston.error('[Instance/%s] Error: Cannot restart stopped instance:', self._model.name, err); }); } });
/** * For testing purpose */ crashRandomInstance() { const names = Array.from(this._managedInstances.keys()); const randomName = names[Math.floor(Math.random() * names.length)]; winston.debug('[Manager] crashRandomInstance: name=%s', randomName); const instance = this._managedInstances.get(randomName); return instance.remove(); }
stop() { winston.debug('[TestServer] stop'); return new Promise((resolve) => { if (!this._child || this._child.killed) { resolve(); } this._child.on('close', () => resolve()); this._child.kill(); this._child = void 0; }); }
proxy .listen() .catch((err) => { winston.error('Cannot start proxy: ', err); process.exit(1); });
removeInstances(models) { winston.debug('[ProviderLocal] removeInstances: models=', _.map(models, (model) => model.toString()) ); return Promise.map(models, (model) => { this._locals.delete(model.providerOpts.name); return this.removeInstance(model); }); }
listen() { return new Promise((resolve, reject) => { this._server.listen(this._config.port, (err) => { if (err) { return reject(new Error(`[Master] Cannot listen at port ${this._config.port} : ${err.toString()}`)); } winston.info('Proxy is listening at http://localhost:%d', this._config.port); return resolve(); }); }); }
removeInstance(model) { winston.debug('[ProviderLocal] removeInstance: model=', model.toString()); return new Promise((resolve) => { const local = model.providerOpts; if (!local.child || local.child.killed) { resolve(); } local.child.on('close', () => resolve()); local.child.kill(); local.child = void 0; }); }
listen() { winston.debug('[Main] listen'); // Start Commander return this._commander .listen() .then(() => { // Start Manager this._manager.start(); // Start Master return this._master.listen(); }); }
_changeAlive(alive) { winston.debug('[Instance/%s] changeAlive: %s => %s', this._model.name, this._alive, alive); if (this._alive !== alive) { this._alive = alive; this.emit('alive:updated', alive); } }
listen() { winston.debug('[LocalProxy/%s] proxy listen at port %d', this._name, this._port); return new Promise((resolve, reject) => { this._server.listen(this._port, (err) => { if (err) { return reject(err); } resolve(); }); }); }