From ca005f92806a3a3af25e260252cb2faabb419d2f Mon Sep 17 00:00:00 2001 From: Thomas Bonnin <233326+TBonnin@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:55:17 -0500 Subject: [PATCH] fix: move triggering actions out of transations When removing failing connection in SlackService, we used to trigger actions in the middle of a db transaction that is locking rows. We also do all sort of async operations like logging. If the actions for instance are experiencing any kind of issue, the transaction is kept open and waiting until the actions times out or the db cancel the transaction. --- .../lib/services/notification/slack.service.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/shared/lib/services/notification/slack.service.ts b/packages/shared/lib/services/notification/slack.service.ts index ad642461c3..54a5d9e1c5 100644 --- a/packages/shared/lib/services/notification/slack.service.ts +++ b/packages/shared/lib/services/notification/slack.service.ts @@ -596,7 +596,7 @@ export class SlackService { environment_id: number; provider: string; }): Promise { - await db.knex.transaction(async (trx) => { + const update = await db.knex.transaction(async (trx) => { const slackNotificationsEnabled = await environmentService.getSlackNotificationsEnabled(nangoConnection.environment_id); if (!slackNotificationsEnabled) { return; @@ -638,7 +638,15 @@ export class SlackService { connection_list, updated_at: new Date() }); + return { + id, + slackTimestamp: slack_timestamp, + adminSlackTimestamp: admin_slack_timestamp, + connectionCount: connection_list.length + }; + }); + if (update) { // we report resolution to the slack channel which could be either // 1) The slack notification is resolved, connection_list === 0 // 2) The list of failing connections has been decremented @@ -649,11 +657,11 @@ export class SlackService { originalActivityLogId, environment_id, provider, - slack_timestamp as string, - admin_slack_timestamp as string, - connection_list.length + update.slackTimestamp as string, + update.adminSlackTimestamp as string, + update.connectionCount ); - }); + } } async closeAllOpenNotificationsForEnv(environment_id: number): Promise {