-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add "pause" method to all connectors (#4558)
* feat: pause connectors * endpoint * front bindings * terminate the workflows * better naming * more instance methods * r --------- Co-authored-by: Henry Fontanier <[email protected]>
- Loading branch information
1 parent
b458004
commit 12bd151
Showing
18 changed files
with
284 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type { WithConnectorsAPIErrorReponse } from "@dust-tt/types"; | ||
import type { Request, Response } from "express"; | ||
|
||
import { PAUSE_CONNECTOR_BY_TYPE } from "@connectors/connectors"; | ||
import { errorFromAny } from "@connectors/lib/error"; | ||
import logger from "@connectors/logger/logger"; | ||
import { apiError, withLogging } from "@connectors/logger/withlogging"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
type ConnectorPauseResBody = WithConnectorsAPIErrorReponse<{ | ||
connectorId: string; | ||
}>; | ||
|
||
const _pauseConnectorAPIHandler = async ( | ||
req: Request<{ connector_id: string }, ConnectorPauseResBody>, | ||
res: Response<ConnectorPauseResBody> | ||
) => { | ||
try { | ||
const connector = await ConnectorResource.fetchById( | ||
req.params.connector_id | ||
); | ||
if (!connector) { | ||
return apiError(req, res, { | ||
api_error: { | ||
type: "connector_not_found", | ||
message: "Connector not found", | ||
}, | ||
status_code: 404, | ||
}); | ||
} | ||
const connectorPauser = PAUSE_CONNECTOR_BY_TYPE[connector.type]; | ||
|
||
const pauseRes = await connectorPauser(connector.id); | ||
|
||
if (pauseRes.isErr()) { | ||
return apiError(req, res, { | ||
status_code: 500, | ||
api_error: { | ||
type: "internal_server_error", | ||
message: pauseRes.error.message, | ||
}, | ||
}); | ||
} | ||
|
||
return res.sendStatus(204); | ||
} catch (e) { | ||
logger.error(errorFromAny(e), "Failed to pause the connector"); | ||
return apiError(req, res, { | ||
status_code: 500, | ||
api_error: { | ||
type: "internal_server_error", | ||
message: "Could not pause the connector", | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
export const pauseConnectorAPIHandler = withLogging(_pauseConnectorAPIHandler); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
connectors/src/connectors/google_drive/pauseGoogleDriveWebhooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { ModelId } from "@dust-tt/types"; | ||
import { Err, Ok } from "@dust-tt/types"; | ||
|
||
import { terminateAllWorkflowsForConnectorId } from "@connectors/lib/temporal"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
export async function pauseGoogleDriveWebhooks(connectorId: ModelId) { | ||
const connector = await ConnectorResource.fetchById(connectorId); | ||
if (!connector) { | ||
return new Err(new Error(`Connector not found with id ${connectorId}`)); | ||
} | ||
await connector.markAsPaused(); | ||
await terminateAllWorkflowsForConnectorId(connectorId); | ||
return new Ok(undefined); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.