Skip to content

Commit e0abbe0

Browse files
committed
wip
1 parent 6ab4f12 commit e0abbe0

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ srf.register(require('./lib/register')({logger}));
260260
srf.options(require('./lib/options')({srf, logger}));
261261

262262
// Start CLI runtime config server with access to srf.locals
263-
require('./lib/cli/runtime-config').initialize(srf.locals);
263+
require('./lib/cli/runtime-config').initialize(srf.locals, logger);
264264

265265
setInterval(async() => {
266266
const count = await srf.locals.registrar.getCountOfUsers();

lib/cli/runtime-config.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const net = require('net');
2-
const logger = require('pino')({ level: process.env.JAMBONES_LOGLEVEL || 'info' });
32

43
const config = new Map();
54
const queue = [];
65
let processing = false;
6+
let logger;
77

88
async function runOperation(operation) {
99
return new Promise((resolve, reject) => {
@@ -31,10 +31,15 @@ async function processQueue() {
3131
}
3232

3333
class RuntimeConfig {
34-
constructor(srfLocals = null) {
34+
constructor(srfLocals = null, appLogger = null) {
3535
this.server = null;
3636
this.socketPath = process.env.SBC_SOCKET_PATH || '/tmp/sbc-sip-sidecar.sock';
3737
this.srfLocals = srfLocals;
38+
if (appLogger) {
39+
logger = appLogger;
40+
} else if (!logger) {
41+
throw new Error('Logger is required for RuntimeConfig');
42+
}
3843
this.startServer();
3944
}
4045

@@ -387,32 +392,36 @@ class RuntimeConfig {
387392

388393
let runtimeConfig = null;
389394

390-
function createInstance(srfLocals = null) {
391-
const instance = new RuntimeConfig(srfLocals);
395+
function createInstance(srfLocals = null, appLogger = null) {
396+
const instance = new RuntimeConfig(srfLocals, appLogger);
392397
process.on('SIGINT', () => instance.shutdown());
393398
process.on('SIGTERM', () => instance.shutdown());
394399
return instance;
395400
}
396401

397-
function initializeRuntimeConfig(srfLocals) {
402+
function initialize(srfLocals, appLogger) {
403+
if (!appLogger) {
404+
throw new Error('Logger is required for RuntimeConfig initialization');
405+
}
398406
if (!runtimeConfig) {
399-
runtimeConfig = createInstance(srfLocals);
407+
runtimeConfig = createInstance(srfLocals, appLogger);
400408
} else {
401-
// Update existing instance with srfLocals
409+
// Update existing instance with srfLocals and logger
402410
runtimeConfig.srfLocals = srfLocals;
411+
logger = appLogger;
403412
}
404413

405414
return runtimeConfig;
406415
}
407416

408417
function getInstance() {
409418
if (!runtimeConfig) {
410-
runtimeConfig = createInstance();
419+
throw new Error('RuntimeConfig not initialized. Call initialize() first with logger.');
411420
}
412421
return runtimeConfig;
413422
}
414423

415424
module.exports = {
416-
initialize: initializeRuntimeConfig,
425+
initialize,
417426
getInstance
418427
};

0 commit comments

Comments
 (0)