diff --git a/.changeset/two-guests-tan.md b/.changeset/two-guests-tan.md new file mode 100644 index 000000000000..ff44f0ef493b --- /dev/null +++ b/.changeset/two-guests-tan.md @@ -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 diff --git a/.changeset/weak-trees-exercise.md b/.changeset/weak-trees-exercise.md new file mode 100644 index 000000000000..230c087ccd83 --- /dev/null +++ b/.changeset/weak-trees-exercise.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/apps-engine': minor +--- + +Add support to configure apps runtime timeout via the APPS_ENGINE_RUNTIME_TIMEOUT environment variable diff --git a/packages/apps-engine/src/server/ProxiedApp.ts b/packages/apps-engine/src/server/ProxiedApp.ts index a63ba3396369..a0aa4594f036 100644 --- a/packages/apps-engine/src/server/ProxiedApp.ts +++ b/packages/apps-engine/src/server/ProxiedApp.ts @@ -57,11 +57,6 @@ export class ProxiedApp { public async call(method: `${AppMethod}`, ...args: Array): Promise { 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) { diff --git a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts index fbb5f0465066..91bb9aee549c 100644 --- a/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts +++ b/packages/apps-engine/src/server/runtime/deno/AppsEngineDenoRuntime.ts @@ -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); } @@ -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;