From e278331e59d36fe032029f22f5076dced1084a4a Mon Sep 17 00:00:00 2001 From: DongHyun Song Date: Fri, 6 Nov 2020 09:39:03 +0900 Subject: [PATCH] [Service][VD] Apply main thread with standalone model With standalone model of service application, this patch will apply main thread service_runner to solve crash problems of node worker. Change-Id: I5fb69368a4bae36ac11d465200b2cd0a42e6c3a1 Signed-off-by: DongHyun Song --- wrt_app/common/service_manager.ts | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/wrt_app/common/service_manager.ts b/wrt_app/common/service_manager.ts index 757688b..14f0a87 100644 --- a/wrt_app/common/service_manager.ts +++ b/wrt_app/common/service_manager.ts @@ -5,14 +5,15 @@ interface WorkerMap { [id: string]: any; } let workers: WorkerMap = {}; +let runner: any; Object.defineProperty(global, 'serviceType', { value: wrt.getServiceModel(), writable: false }); -function isServiceApplication() { - return global['serviceType'] !== 'UI'; +function isStandalone() { + return global['serviceType'] === 'STANDALONE'; } function createWorker(id: string, startService: string, filename: string) { @@ -48,13 +49,26 @@ function terminateWorker(id: string, delay: number) { export function startService(id: string, filename: string) { console.log(`startService - ${id}`); - let startService = `${__dirname}/service_runner.js`; - createWorker(id, startService, filename); + if (isStandalone()) { + runner = require('../common/service_runner'); + runner.start(id, filename); + } else { + let startService = `${__dirname}/service_runner.js`; + createWorker(id, startService, filename); + } } export function stopService(id: string) { console.log(`stopService - ${id}`); - terminateWorker(id, 500); + if (isStandalone()) { + if (!runner) { + console.log('runner instance is null in standalone mode'); + return; + } + runner.stop(id); + } else { + terminateWorker(id, 500); + } } export function handleBuiltinService(serviceId: string, serviceName: string) { -- 2.7.4