From eb794b7fd6bf3ff5a37a38bccaba247ed36db744 Mon Sep 17 00:00:00 2001 From: Douglas Gubert Date: Thu, 12 Dec 2024 18:14:20 -0300 Subject: [PATCH] fix: app subprocess restart not running onEnable lifecycle (#34172) --- .changeset/chilled-seas-refuse.md | 5 +++++ packages/apps-engine/src/server/AppManager.ts | 8 ++++++++ .../src/server/runtime/deno/AppsEngineDenoRuntime.ts | 8 ++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 .changeset/chilled-seas-refuse.md diff --git a/.changeset/chilled-seas-refuse.md b/.changeset/chilled-seas-refuse.md new file mode 100644 index 000000000000..d4066938513d --- /dev/null +++ b/.changeset/chilled-seas-refuse.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/apps-engine': patch +--- + +Fixes the subprocess restarting routine failing to correctly restart apps in some cases diff --git a/packages/apps-engine/src/server/AppManager.ts b/packages/apps-engine/src/server/AppManager.ts index 963b90a39a6b..0bb930b723a1 100644 --- a/packages/apps-engine/src/server/AppManager.ts +++ b/packages/apps-engine/src/server/AppManager.ts @@ -1035,6 +1035,10 @@ export class AppManager { result = false; await app.setStatus(status, silenceStatus); + + // If some error has happened in initialization, like license or installations invalidation + // we need to store this on the DB regardless of what the parameter requests + saveToDb = true; } if (saveToDb) { @@ -1113,6 +1117,10 @@ export class AppManager { } console.error(e); + + // If some error has happened during enabling, like license or installations invalidation + // we need to store this on the DB regardless of what the parameter requests + saveToDb = true; } if (enable) { diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index 458799286c83..22608962bcf7 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -9,14 +9,14 @@ import { LivenessManager } from './LivenessManager'; import { ProcessMessenger } from './ProcessMessenger'; import { bundleLegacyApp } from './bundler'; import { decoder } from './codec'; -import { AppStatus } from '../../../definition/AppStatus'; +import { AppStatus, AppStatusUtils } from '../../../definition/AppStatus'; +import type { AppMethod } from '../../../definition/metadata'; import type { AppManager } from '../../AppManager'; import type { AppBridges } from '../../bridges'; import type { IParseAppPackageResult } from '../../compiler'; import { AppConsole, type ILoggerStorageEntry } from '../../logging'; import type { AppAccessorManager, AppApiManager } from '../../managers'; import type { AppLogStorage, IAppStorageItem } from '../../storage'; -import { AppMethod } from '../../../definition/metadata'; const baseDebug = debugFactory('appsEngine:runtime:deno'); @@ -287,6 +287,10 @@ export class DenoRuntimeSubprocessController extends EventEmitter { await this.sendRequest({ method: 'app:initialize' }); await this.sendRequest({ method: 'app:setStatus', params: [this.storageItem.status] }); + if (AppStatusUtils.isEnabled(this.storageItem.status)) { + await this.sendRequest({ method: 'app:onEnable' }); + } + this.state = 'ready'; logger.info('Successfully restarted app subprocess');