From: DongHyun Song Date: Mon, 28 Sep 2020 06:32:06 +0000 (+0900) Subject: [Service] Apply node worker for standalone model X-Git-Tag: submit/tizen/20201005.132203^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b011acf4a65ec8b940605ddeb53cc3709f2009d;p=platform%2Fframework%2Fweb%2Fwrtjs.git [Service] Apply node worker for standalone model This change is implemented for 1) unify source code with global model 2) isolate v8 variable scope from main thread - standalone service application cannot get main global variable of service_manaer / service_runner There is no noticeable memory increase with node worker. Change-Id: I7bb4576026ce326a3903987c537810093db028b4 Signed-off-by: DongHyun Song --- diff --git a/wrt_app/common/service_manager.ts b/wrt_app/common/service_manager.ts index 3038364e..c4b29401 100644 --- a/wrt_app/common/service_manager.ts +++ b/wrt_app/common/service_manager.ts @@ -5,16 +5,11 @@ interface WorkerMap { [id: string]: any; } let workers: WorkerMap = {}; -let runner: any; global.serviceType = wrt.getServiceModel(); -function isStandalone() { - return global.serviceType === 'STANDALONE'; -} - -function isGlobalService() { - return global.serviceType === 'DAEMON'; +function isServiceApplication() { + return global.serviceType !== 'UI'; } function createWorker(id: string, startService: string, filename: string) { @@ -37,7 +32,7 @@ function terminateWorker(id: string, delay: number) { delete workers[id]; let runningServices = Object.keys(workers).length; console.log('Running services : ' + runningServices); - if (runningServices === 0 && isGlobalService()) { + if (runningServices === 0 && isServiceApplication()) { process.exit(); } } @@ -46,29 +41,15 @@ function terminateWorker(id: string, delay: number) { export function startService(id: string, filename: string) { console.log(`startService - ${id}`); - if (isStandalone()) { - runner = require('../common/service_runner'); - runner.start(id, filename); - } else { - if (isMainThread) { - let startService = `${__dirname}/service_runner.js`; - createWorker(id, startService, filename); - } + if (isMainThread) { + let startService = `${__dirname}/service_runner.js`; + createWorker(id, startService, filename); } } export function stopService(id: string) { console.log(`stopService - ${id}`); - if (isStandalone()) { - if (!runner) { - console.log('runner instance is null in standalone mode'); - return; - } - runner.stop(id); - setTimeout(() => process.exit(), 500); - } else { - terminateWorker(id, 500); - } + terminateWorker(id, 500); } export function handleBuiltinService(serviceId: string, serviceName: string) { diff --git a/wrt_app/service/main.ts b/wrt_app/service/main.ts index b0c371a0..c64591e4 100755 --- a/wrt_app/service/main.ts +++ b/wrt_app/service/main.ts @@ -27,9 +27,6 @@ wrt.on('start-service', (event: any, internal_id: string) => { wrt.on('stop-service', (event: any, internal_id: string) => { ServiceManager.stopService(internal_id); - if (wrt.getServiceModel() === 'STANDALONE') { - setTimeout(() => {process.exit()}, 10); - } }); wrt.on('builtin-service', (event: any, internal_id: string, service_name: string) => {