Skip to content

Commit

Permalink
move the upsertion to an activity
Browse files Browse the repository at this point in the history
  • Loading branch information
aubin-tchoi committed Dec 19, 2024
1 parent a41b0a9 commit ca11df9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
13 changes: 0 additions & 13 deletions connectors/src/connectors/google_drive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ import {
BaseConnectorManager,
ConnectorManagerError,
} from "@connectors/connectors/interface";
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config";
import { concurrentExecutor } from "@connectors/lib/async_utils";
import { upsertDataSourceFolder } from "@connectors/lib/data_sources";
import {
GoogleDriveConfig,
GoogleDriveFiles,
Expand Down Expand Up @@ -131,17 +129,6 @@ export class GoogleDriveConnectorManager extends BaseConnectorManager<null> {
googleDriveConfigurationBlob
);

// Upserts to data_sources_folders (core) a top-level folder "Shared with me".
const folderId = getInternalId(GOOGLE_DRIVE_SHARED_WITH_ME_VIRTUAL_ID);
await upsertDataSourceFolder({
dataSourceConfig: dataSourceConfigFromConnector(connector),
folderId,
parents: [folderId],
parentId: null,
title: "Shared with me",
mimeType: "application/vnd.dust.googledrive.folder",
});

// We mark it artificially as sync succeeded as google drive is created empty.
await syncSucceeded(connector.id);

Expand Down
25 changes: 24 additions & 1 deletion connectors/src/connectors/google_drive/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import StatsD from "hot-shots";
import PQueue from "p-queue";
import { Op } from "sequelize";

import { GOOGLE_DRIVE_USER_SPACE_VIRTUAL_DRIVE_ID } from "@connectors/connectors/google_drive/lib/consts";
import {
GOOGLE_DRIVE_SHARED_WITH_ME_VIRTUAL_ID,
GOOGLE_DRIVE_USER_SPACE_VIRTUAL_DRIVE_ID,
} from "@connectors/connectors/google_drive/lib/consts";
import { getGoogleDriveObject } from "@connectors/connectors/google_drive/lib/google_drive_api";
import { getFileParentsMemoized } from "@connectors/connectors/google_drive/lib/hierarchy";
import { syncOneFile } from "@connectors/connectors/google_drive/temporal/file";
Expand Down Expand Up @@ -54,6 +57,26 @@ type LightGoogleDrive = {

export const statsDClient = new StatsD();

/**
* Upserts to data_sources_folders (core) a top-level folder "Shared with me".
*/
export async function upsertSharedWithMeFolder(connectorId: ModelId) {
const connector = await ConnectorResource.fetchById(connectorId);
if (!connector) {
throw new Error(`Connector ${connectorId} not found`);
}

const folderId = getInternalId(GOOGLE_DRIVE_SHARED_WITH_ME_VIRTUAL_ID);
await upsertDataSourceFolder({
dataSourceConfig: dataSourceConfigFromConnector(connector),
folderId,
parents: [folderId],
parentId: null,
title: "Shared with me",
mimeType: "application/vnd.dust.googledrive.folder",
});
}

export async function getDrives(
connectorId: ModelId
): Promise<LightGoogleDrive[]> {
Expand Down
3 changes: 3 additions & 0 deletions connectors/src/connectors/google_drive/temporal/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const {
garbageCollectorFinished,
markFolderAsVisited,
shouldGarbageCollect,
upsertSharedWithMeFolder,
} = proxyActivities<typeof activities>({
startToCloseTimeout: "20 minutes",
});
Expand Down Expand Up @@ -104,6 +105,8 @@ export async function googleDriveFullSync({
}
});

await upsertSharedWithMeFolder(connectorId);

// Temp to clean up the running workflows state
foldersToBrowse = uniq(foldersToBrowse);

Expand Down

0 comments on commit ca11df9

Please sign in to comment.