From 5a154451bd6aeab306971158c9ca44260c164503 Mon Sep 17 00:00:00 2001 From: Thomas Bonnin <233326+TBonnin@users.noreply.github.com> Date: Wed, 27 Nov 2024 16:09:56 -0500 Subject: [PATCH] fix: do not wait for on-event script to finish when triggering them (#3075) on-event scripts don't have output so waiting for them to finish is not necessary. Also modifying the max duration timeout to 5mins for on-event script How to test: - modify your on-event script to sleep. Ex: ``` const waitTime = 10; for (let i = 0; i < waitTime; i++) { await nango.log(`Countdown: ${waitTime - i}`); await new Promise((resolve) => setTimeout(resolve, 1000)); } ``` - create/delete a connection and then check in the logs dashboard that the script is still running and you didn't have to wait for it --- packages/jobs/lib/execution/onEvent.ts | 2 +- packages/orchestrator/lib/clients/client.ts | 15 +++++++++++++-- .../lib/hooks/connection/on/connection-created.ts | 2 -- .../lib/hooks/connection/on/connection-deleted.ts | 2 -- packages/shared/lib/clients/orchestrator.ts | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/packages/jobs/lib/execution/onEvent.ts b/packages/jobs/lib/execution/onEvent.ts index 02d626baf7..5bb5f81d94 100644 --- a/packages/jobs/lib/execution/onEvent.ts +++ b/packages/jobs/lib/execution/onEvent.ts @@ -110,7 +110,7 @@ export async function startOnEvent(task: TaskOnEvent): Promise> { } export async function handleOnEventSuccess({ nangoProps }: { nangoProps: NangoProps }): Promise { - const content = `Webhook "${nangoProps.syncConfig.sync_name}" has been run successfully.`; + const content = `Script "${nangoProps.syncConfig.sync_name}" has been run successfully.`; void bigQueryClient.insert({ executionType: 'on-event', connectionId: nangoProps.connectionId, diff --git a/packages/orchestrator/lib/clients/client.ts b/packages/orchestrator/lib/clients/client.ts index f8d691f026..544ff6e030 100644 --- a/packages/orchestrator/lib/clients/client.ts +++ b/packages/orchestrator/lib/clients/client.ts @@ -254,17 +254,28 @@ export class OrchestratorClient { return this.execute(schedulingProps); } - public async executeOnEvent(props: ExecuteOnEventProps): Promise { + public async executeOnEvent(props: ExecuteOnEventProps): Promise { const { args, ...rest } = props; const schedulingProps = { + retry: { count: 0, max: 0 }, + timeoutSettingsInSecs: { + createdToStarted: 30, + startedToCompleted: 5 * 60, + heartbeat: 99999 + }, ...rest, args: { ...args, type: 'on-event' as const } }; - return this.execute(schedulingProps); + const res = await this.immediate(schedulingProps); + if (res.isErr()) { + return Err(res.error); + } + return Ok(undefined); } + public async searchTasks({ ids, groupKey, diff --git a/packages/server/lib/hooks/connection/on/connection-created.ts b/packages/server/lib/hooks/connection/on/connection-created.ts index 2ddc193ba4..c2f16583c6 100644 --- a/packages/server/lib/hooks/connection/on/connection-created.ts +++ b/packages/server/lib/hooks/connection/on/connection-created.ts @@ -50,8 +50,6 @@ export async function postConnectionCreation( }); if (res.isErr()) { await logCtx.failed(); - } else { - await logCtx.success(); } } } diff --git a/packages/server/lib/hooks/connection/on/connection-deleted.ts b/packages/server/lib/hooks/connection/on/connection-deleted.ts index 74e24ae604..5f4a08c24a 100644 --- a/packages/server/lib/hooks/connection/on/connection-deleted.ts +++ b/packages/server/lib/hooks/connection/on/connection-deleted.ts @@ -52,8 +52,6 @@ export async function preConnectionDeletion({ }); if (res.isErr()) { await logCtx.failed(); - } else { - await logCtx.success(); } } } diff --git a/packages/shared/lib/clients/orchestrator.ts b/packages/shared/lib/clients/orchestrator.ts index 5b6ba3247a..b3633a9e83 100644 --- a/packages/shared/lib/clients/orchestrator.ts +++ b/packages/shared/lib/clients/orchestrator.ts @@ -52,7 +52,7 @@ export interface OrchestratorClientInterface { recurring(props: RecurringProps): Promise>; executeAction(props: ExecuteActionProps): Promise; executeWebhook(props: ExecuteWebhookProps): Promise; - executeOnEvent(props: ExecuteOnEventProps): Promise; + executeOnEvent(props: ExecuteOnEventProps): Promise; executeSync(props: ExecuteSyncProps): Promise; pauseSync({ scheduleName }: { scheduleName: string }): Promise; unpauseSync({ scheduleName }: { scheduleName: string }): Promise;