Skip to content

Commit

Permalink
fix: do not wait for on-event script to finish when triggering them (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
TBonnin authored Nov 27, 2024
1 parent 1445793 commit 5a15445
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/jobs/lib/execution/onEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export async function startOnEvent(task: TaskOnEvent): Promise<Result<void>> {
}

export async function handleOnEventSuccess({ nangoProps }: { nangoProps: NangoProps }): Promise<void> {
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,
Expand Down
15 changes: 13 additions & 2 deletions packages/orchestrator/lib/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,28 @@ export class OrchestratorClient {
return this.execute(schedulingProps);
}

public async executeOnEvent(props: ExecuteOnEventProps): Promise<ExecuteReturn> {
public async executeOnEvent(props: ExecuteOnEventProps): Promise<VoidReturn> {
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,
Expand Down
2 changes: 0 additions & 2 deletions packages/server/lib/hooks/connection/on/connection-created.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export async function postConnectionCreation(
});
if (res.isErr()) {
await logCtx.failed();
} else {
await logCtx.success();
}
}
}
2 changes: 0 additions & 2 deletions packages/server/lib/hooks/connection/on/connection-deleted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export async function preConnectionDeletion({
});
if (res.isErr()) {
await logCtx.failed();
} else {
await logCtx.success();
}
}
}
2 changes: 1 addition & 1 deletion packages/shared/lib/clients/orchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface OrchestratorClientInterface {
recurring(props: RecurringProps): Promise<Result<{ scheduleId: string }>>;
executeAction(props: ExecuteActionProps): Promise<ExecuteReturn>;
executeWebhook(props: ExecuteWebhookProps): Promise<ExecuteReturn>;
executeOnEvent(props: ExecuteOnEventProps): Promise<ExecuteReturn>;
executeOnEvent(props: ExecuteOnEventProps): Promise<VoidReturn>;
executeSync(props: ExecuteSyncProps): Promise<VoidReturn>;
pauseSync({ scheduleName }: { scheduleName: string }): Promise<VoidReturn>;
unpauseSync({ scheduleName }: { scheduleName: string }): Promise<VoidReturn>;
Expand Down

0 comments on commit 5a15445

Please sign in to comment.