Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: engine restart process for Deno used wrong status #33865

Merged
merged 9 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-coins-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/apps-engine': patch
---

Fixed an issue that would cause apps to appear disabled after a subprocess restart
2 changes: 1 addition & 1 deletion packages/apps-engine/src/server/compiler/AppCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AppCompiler {
throw new Error(`Invalid App package for "${storage.info.name}". Could not find the classFile (${storage.info.classFile}) file.`);
}

const runtime = await manager.getRuntime().startRuntimeForApp(packageResult);
const runtime = await manager.getRuntime().startRuntimeForApp(packageResult, storage);

const app = new ProxiedApp(manager, storage, runtime);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { AppManager } from '../AppManager';
import type { IParseAppPackageResult } from '../compiler';
import { DenoRuntimeSubprocessController } from '../runtime/deno/AppsEngineDenoRuntime';
import type { IAppStorageItem } from '../storage';

export type AppRuntimeParams = {
appId: string;
Expand All @@ -21,14 +22,18 @@ export class AppRuntimeManager {

constructor(private readonly manager: AppManager) {}

public async startRuntimeForApp(appPackage: IParseAppPackageResult, options = { force: false }): Promise<DenoRuntimeSubprocessController> {
public async startRuntimeForApp(
appPackage: IParseAppPackageResult,
storageItem: IAppStorageItem,
options = { force: false },
): Promise<DenoRuntimeSubprocessController> {
const { id: appId } = appPackage.info;

if (appId in this.subprocesses && !options.force) {
throw new Error('App already has an associated runtime');
}

this.subprocesses[appId] = new DenoRuntimeSubprocessController(this.manager, appPackage);
this.subprocesses[appId] = new DenoRuntimeSubprocessController(this.manager, appPackage, storageItem);

await this.subprocesses[appId].setupApp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { AppBridges } from '../../bridges';
import type { IParseAppPackageResult } from '../../compiler';
import type { ILoggerStorageEntry } from '../../logging';
import type { AppAccessorManager, AppApiManager } from '../../managers';
import type { AppLogStorage } from '../../storage';
import type { AppLogStorage, IAppStorageItem } from '../../storage';
import { LivenessManager } from './LivenessManager';
import { ProcessMessenger } from './ProcessMessenger';
import { bundleLegacyApp } from './bundler';
Expand Down Expand Up @@ -97,6 +97,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
constructor(
manager: AppManager,
private readonly appPackage: IParseAppPackageResult,
private readonly storageItem: IAppStorageItem,
) {
super();

Expand Down Expand Up @@ -249,6 +250,8 @@ export class DenoRuntimeSubprocessController extends EventEmitter {

await this.sendRequest({ method: 'app:initialize' });

await this.sendRequest({ method: 'app:setStatus', params: [this.storageItem.status] });

this.state = 'ready';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const defaultOptions: LivenessManager['options'] = {
pingRequestTimeout: 10000,
pingFrequencyInMS: 10000,
consecutiveTimeoutLimit: 4,
maxRestarts: 3,
maxRestarts: Infinity,
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import * as path from 'path';
import { TestFixture, Setup, Expect, AsyncTest, SpyOn, Any, AsyncSetupFixture, Teardown } from 'alsatian';
import type { SuccessObject } from 'jsonrpc-lite';

import { AppStatus } from '../../../src/definition/AppStatus';
import { UserStatusConnection, UserType } from '../../../src/definition/users';
import type { AppManager } from '../../../src/server/AppManager';
import type { IParseAppPackageResult } from '../../../src/server/compiler';
import { AppAccessorManager, AppApiManager } from '../../../src/server/managers';
import { DenoRuntimeSubprocessController } from '../../../src/server/runtime/deno/AppsEngineDenoRuntime';
import type { IAppStorageItem } from '../../../src/server/storage';
import { TestInfastructureSetup } from '../../test-data/utilities';

@TestFixture('DenoRuntimeSubprocessController')
@TestFixture()
export class DenuRuntimeSubprocessControllerTestFixture {
private manager: AppManager;

private controller: DenoRuntimeSubprocessController;

private appPackage: IParseAppPackageResult;

private appStorageItem: IAppStorageItem;

@AsyncSetupFixture
public async fixture() {
const infrastructure = new TestInfastructureSetup();
Expand All @@ -35,11 +39,16 @@ export class DenuRuntimeSubprocessControllerTestFixture {
const appPackage = await fs.readFile(path.join(__dirname, '../../test-data/apps/hello-world-test_0.0.1.zip'));

this.appPackage = await this.manager.getParser().unpackageApp(appPackage);

this.appStorageItem = {
id: 'hello-world-test',
status: AppStatus.MANUALLY_ENABLED,
} as IAppStorageItem;
}

@Setup
public setup() {
this.controller = new DenoRuntimeSubprocessController(this.manager, this.appPackage);
this.controller = new DenoRuntimeSubprocessController(this.manager, this.appPackage, this.appStorageItem);
this.controller.setupApp();
}

Expand Down
Loading