Skip to content

Commit

Permalink
Start sync workflow after transaction.commit() (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Oct 5, 2023
1 parent f6d46ef commit 9dda1f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
21 changes: 11 additions & 10 deletions connectors/src/connectors/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ export async function createGithubConnector(
if (!(await validateInstallationId(githubInstallationId))) {
return new Err(new Error("Github installation id is invalid"));
}

return await sequelize_conn.transaction(async (transaction) => {
try {
try {
const connector = await sequelize_conn.transaction(async (transaction) => {
const connector = await Connector.create(
{
type: "github",
Expand All @@ -57,14 +56,16 @@ export async function createGithubConnector(
},
{ transaction }
);
await launchGithubFullSyncWorkflow(connector.id.toString());
return new Ok(connector.id.toString());
} catch (err) {
logger.error({ error: err }, "Error creating github connector");

return new Err(err as Error);
}
});
return connector;
});
await launchGithubFullSyncWorkflow(connector.id.toString());
return new Ok(connector.id.toString());
} catch (err) {
logger.error({ error: err }, "Error creating github connector");

return new Err(err as Error);
}
}

export async function updateGithubConnector(
Expand Down
8 changes: 5 additions & 3 deletions connectors/src/connectors/notion/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function createNotionConnector(
}

try {
return await sequelize_conn.transaction(async (transaction) => {
const connector = await sequelize_conn.transaction(async (transaction) => {
const connector = await Connector.create(
{
type: "notion",
Expand All @@ -73,9 +73,11 @@ export async function createNotionConnector(
},
{ transaction }
);
await launchNotionSyncWorkflow(connector.id.toString());
return new Ok(connector.id.toString());

return connector;
});
await launchNotionSyncWorkflow(connector.id.toString());
return new Ok(connector.id.toString());
} catch (e) {
logger.error({ error: e }, "Error creating notion connector.");
return new Err(e as Error);
Expand Down

0 comments on commit 9dda1f7

Please sign in to comment.