Skip to content

Commit

Permalink
feat: apps-engine timeout config (#33690)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gubert authored Nov 4, 2024
1 parent 06189eb commit d398866
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-guests-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/apps-engine': patch
---

Removed the 1 second timeout of `Pre` app events. Now they will follow the "global" configuration
5 changes: 5 additions & 0 deletions .changeset/weak-trees-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/apps-engine': minor
---

Add support to configure apps runtime timeout via the APPS_ENGINE_RUNTIME_TIMEOUT environment variable
5 changes: 0 additions & 5 deletions packages/apps-engine/src/server/ProxiedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ export class ProxiedApp {
public async call(method: `${AppMethod}`, ...args: Array<any>): Promise<any> {
let options;

// Pre events need to be fast as they block the user
if (method.startsWith('checkPre') || method.startsWith('executePre')) {
options = { timeout: 1000 };
}

try {
return await this.appRuntime.sendRequest({ method: `app:${method}`, params: args }, options);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,18 @@ const COMMAND_PONG = '_zPONG';

export const JSONRPC_METHOD_NOT_FOUND = -32601;

export function getRuntimeTimeout() {
const defaultTimeout = 30000;
const envValue = isFinite(process.env.APPS_ENGINE_RUNTIME_TIMEOUT as any) ? Number(process.env.APPS_ENGINE_RUNTIME_TIMEOUT) : defaultTimeout;

if (envValue < 0) {
console.log('Environment variable APPS_ENGINE_RUNTIME_TIMEOUT has a negative value, ignoring...');
return defaultTimeout;
}

return envValue;
}

export function isValidOrigin(accessor: string): accessor is (typeof ALLOWED_ACCESSOR_METHODS)[number] {
return ALLOWED_ACCESSOR_METHODS.includes(accessor as any);
}
Expand All @@ -78,7 +90,7 @@ export class DenoRuntimeSubprocessController extends EventEmitter {
private readonly debug: debug.Debugger;

private readonly options = {
timeout: 10000,
timeout: getRuntimeTimeout(),
};

private readonly accessors: AppAccessorManager;
Expand Down

0 comments on commit d398866

Please sign in to comment.