Skip to content

Commit

Permalink
fix: app subprocess restart not running onEnable lifecycle (#34173)
Browse files Browse the repository at this point in the history
Co-authored-by: Douglas Gubert <1810309+d-gubert@users.noreply.github.com>
  • Loading branch information
dionisio-bot[bot] and d-gubert authored Dec 12, 2024
1 parent 78e0010 commit 6da9df6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-seas-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/apps-engine': patch
---

Fixes the subprocess restarting routine failing to correctly restart apps in some cases
8 changes: 8 additions & 0 deletions packages/apps-engine/src/server/AppManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,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) {
Expand Down Expand Up @@ -1111,6 +1115,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { type Readable, EventEmitter } from 'stream';
import debugFactory from 'debug';
import * as jsonrpc from 'jsonrpc-lite';

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';
Expand Down Expand Up @@ -286,6 +286,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');
Expand Down

0 comments on commit 6da9df6

Please sign in to comment.