Skip to content

Commit

Permalink
[Gdrive] Support old and new webhook system. (#4721)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasryaric authored Apr 15, 2024
1 parent 084e149 commit cd996b4
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions connectors/src/api/webhooks/webhook_google_drive.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { WithConnectorsAPIErrorReponse } from "@dust-tt/types";
import type { ModelId, WithConnectorsAPIErrorReponse } from "@dust-tt/types";
import { RateLimitError } from "@dust-tt/types";
import type { Request, Response } from "express";

Expand Down Expand Up @@ -33,16 +33,28 @@ const _webhookGoogleDriveAPIHandler = async (
webhookId: channelId,
},
});
if (!webhook) {

let connectorId: ModelId | null = null;
let webhookId: string | null = null;
if (webhook) {
connectorId = webhook.connectorId;
webhookId = webhook.webhookId;
} else if (
req.params.connector_id &&
typeof req.params.connector_id === "string"
) {
connectorId = parseInt(req.params.connector_id);
}
if (!connectorId) {
return apiError(req, res, {
status_code: 404,
status_code: 400,
api_error: {
message: "Webhook not found",
message: "Could not determine connectorId from webhook",
type: "invalid_request_error",
},
});
}
const connector = await ConnectorResource.fetchById(webhook.connectorId);
const connector = await ConnectorResource.fetchById(connectorId);
if (!connector) {
return apiError(req, res, {
status_code: 404,
Expand All @@ -55,24 +67,24 @@ const _webhookGoogleDriveAPIHandler = async (
if (connector.isPaused()) {
logger.info(
{
connectorId: webhook.connectorId,
webhookId: webhook.webhookId,
connectorId: connectorId,
webhookId: webhookId,
},
"Did not signal a Gdrive webhook to the incremenal sync workflow because the connector is paused"
);
return res.status(200).end();
}

const workflowRes = await launchGoogleDriveIncrementalSyncWorkflow(
webhook.connectorId
connectorId
);

if (workflowRes.isErr()) {
if (workflowRes.error instanceof RateLimitError) {
logger.info(
{
connectorId: webhook.connectorId,
webhookId: webhook.webhookId,
connectorId: connectorId,
webhookId: webhookId,
},
"Did not signal a Gdrive webhook to the incremenal sync workflow because of rate limit"
);
Expand Down

0 comments on commit cd996b4

Please sign in to comment.