Comparing version 3.0.10 to 3.0.11
@@ -18,3 +18,3 @@ 'use strict'; | ||
const WORKER_PATH = path.join(__dirname, 'lib/worker.js'); | ||
const REPORTER_PATH = path.join(__dirname, 'lib/reporter.js'); | ||
const REPORTER_PATH = 'file://' + path.join(__dirname, 'lib/reporter.js'); | ||
const LOG_PATH = path.join(PATH, 'log'); | ||
@@ -21,0 +21,0 @@ const CTRL_C = 3; |
'use strict'; | ||
const { node, npm, metarhia, wt } = require('./deps.js'); | ||
const { MessageChannel, parentPort, threadId, workerData } = wt; | ||
const { parentPort, threadId, workerData } = wt; | ||
const { Error, DomainError, Semaphore } = metarhia.metautil; | ||
@@ -17,25 +17,4 @@ const { EventEmitter } = node.events; | ||
const invoke = async ({ method, args, exclusive = false }) => { | ||
const { port1: port, port2 } = new MessageChannel(); | ||
const data = { method, args }; | ||
const msg = { name: 'invoke', exclusive, data, port }; | ||
return new Promise((resolve, reject) => { | ||
port2.on('message', ({ error, data }) => { | ||
port2.close(); | ||
if (error) reject(error); | ||
else resolve(data); | ||
}); | ||
parentPort.postMessage(msg, [port]); | ||
}); | ||
}; | ||
const UserApplication = class Application extends EventEmitter {}; | ||
const UserApplication = class Application extends EventEmitter { | ||
constructor(app, data) { | ||
super(); | ||
Object.assign(this, data); | ||
this.introspect = async (units) => app.introspect(units); | ||
this.invoke = invoke; | ||
} | ||
}; | ||
const { COMMON_CONTEXT } = metarhia.metavm; | ||
@@ -149,3 +128,3 @@ const ERRORS = { Error, DomainError }; | ||
console.error('🔴 Test execution timed out'); | ||
wt.parentPort.postMessage({ name: 'terminate', code: 1 }); | ||
parentPort.postMessage({ name: 'terminate', code: 1 }); | ||
}, config.server.timeouts.test); | ||
@@ -162,3 +141,3 @@ await node.events.once(this, 'ready'); | ||
const code = failed === 0 ? 0 : 1; | ||
wt.parentPort.postMessage({ name: 'terminate', code }); | ||
parentPort.postMessage({ name: 'terminate', code }); | ||
} | ||
@@ -180,4 +159,6 @@ | ||
const server = { host, port: workerData.port, protocol }; | ||
const userAppData = { worker, server, resources, schemas, scheduler }; | ||
const application = new UserApplication(this, userAppData); | ||
const application = new UserApplication(); | ||
const introspect = async (units) => this.introspect(units); | ||
const data = { worker, server, resources, schemas, scheduler, introspect }; | ||
Object.assign(application, data); | ||
const sandbox = { ...SANDBOX, console, application, config }; | ||
@@ -184,0 +165,0 @@ sandbox.api = {}; |
'use strict'; | ||
const { node, metarhia, notLoaded, wt } = require('./deps.js'); | ||
const { MessageChannel, parentPort, threadId, workerData } = wt; | ||
const application = require('./application.js'); | ||
@@ -12,3 +14,3 @@ | ||
if (application.initialization) { | ||
console.info(`Initialization failed in worker ${wt.threadId}`); | ||
console.info(`Initialization failed in worker ${threadId}`); | ||
await application.shutdown(); | ||
@@ -24,37 +26,29 @@ process.exit(0); | ||
(async () => { | ||
const cfgPath = node.path.join(application.path, 'config'); | ||
const context = metarhia.metavm.createContext({ process }); | ||
const cfgOptions = { mode: process.env.MODE, context }; | ||
const { Config } = metarhia.metaconfiguration; | ||
const config = await new Config(cfgPath, cfgOptions); | ||
const logPath = node.path.join(application.root, 'log'); | ||
const home = application.root; | ||
const workerId = wt.threadId; | ||
const logOptions = { path: logPath, workerId, ...config.log, home }; | ||
const logger = await new metarhia.metalog.Logger(logOptions); | ||
logger.on('error', logError('logger error')); | ||
if (logger.active) global.console = logger.console; | ||
Object.assign(application, { config, logger, console }); | ||
const invoke = async ({ method, args, exclusive = false }) => { | ||
const { port1: port, port2 } = new MessageChannel(); | ||
const data = { method, args }; | ||
const msg = { name: 'invoke', exclusive, data, port }; | ||
return new Promise((resolve, reject) => { | ||
port2.on('message', ({ error, data }) => { | ||
port2.close(); | ||
if (error) reject(error); | ||
else resolve(data); | ||
}); | ||
parentPort.postMessage(msg, [port]); | ||
}); | ||
}; | ||
if (notLoaded.size > 0) { | ||
if (wt.threadId === 1) { | ||
const libs = Array.from(notLoaded).join(', '); | ||
console.error(`Can not load modules: ${libs}`); | ||
} | ||
process.exit(0); | ||
} | ||
const ready = async () => { | ||
const handlers = { | ||
ready: async () => { | ||
application.emit('ready'); | ||
}; | ||
}, | ||
const stop = async () => { | ||
stop: async () => { | ||
if (application.finalization) return; | ||
console.info(`Graceful shutdown in worker ${wt.threadId}`); | ||
console.info(`Graceful shutdown in worker ${threadId}`); | ||
await application.shutdown(); | ||
process.exit(0); | ||
}; | ||
}, | ||
const invoke = async ({ exclusive, data, port }) => { | ||
invoke: async ({ exclusive, data, port }) => { | ||
const { method, args } = data; | ||
@@ -75,16 +69,39 @@ const { sandbox } = application; | ||
} finally { | ||
if (exclusive) wt.parentPort.postMessage(msg); | ||
if (exclusive) parentPort.postMessage(msg); | ||
} | ||
}; | ||
}, | ||
}; | ||
const handlers = { ready, stop, invoke }; | ||
wt.parentPort.on('message', async (msg) => { | ||
const handler = handlers[msg.name]; | ||
if (handler) handler(msg); | ||
}); | ||
parentPort.on('message', async (msg) => { | ||
const handler = handlers[msg.name]; | ||
if (handler) handler(msg); | ||
}); | ||
(async () => { | ||
const cfgPath = node.path.join(application.path, 'config'); | ||
const context = metarhia.metavm.createContext({ process }); | ||
const cfgOptions = { mode: process.env.MODE, context }; | ||
const { Config } = metarhia.metaconfiguration; | ||
const config = await new Config(cfgPath, cfgOptions); | ||
const logPath = node.path.join(application.root, 'log'); | ||
const home = application.root; | ||
const logOptions = { path: logPath, workerId: threadId, ...config.log, home }; | ||
const logger = await new metarhia.metalog.Logger(logOptions); | ||
logger.on('error', logError('logger error')); | ||
if (logger.active) global.console = logger.console; | ||
Object.assign(application, { config, logger, console }); | ||
if (notLoaded.size > 0) { | ||
if (threadId === 1) { | ||
const libs = Array.from(notLoaded).join(', '); | ||
console.error(`Can not load modules: ${libs}`); | ||
} | ||
process.exit(0); | ||
} | ||
await application.load(); | ||
application.sandbox.application.invoke = invoke; | ||
await application.start(); | ||
console.info(`Application started in worker ${wt.threadId}`); | ||
wt.parentPort.postMessage({ name: 'started', kind: wt.workerData.kind }); | ||
})().catch(logError(`Can not start worker ${wt.threadId}`)); | ||
console.info(`Application started in worker ${threadId}`); | ||
parentPort.postMessage({ name: 'started', kind: workerData.kind }); | ||
})().catch(logError(`Can not start worker ${threadId}`)); |
{ | ||
"name": "impress", | ||
"version": "3.0.10", | ||
"version": "3.0.11", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Enterprise application server for Node.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68536
1798