Workspace Folder Deletion Error - add logs for investigation (#13385)
https://twenty-v7.sentry.io/issues/6565008010/events/latest/?environment=prod&project=4507072499810304&referrer=latest-event&sort=date related to https://github.com/twentyhq/twenty/issues/12299
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
import fs from 'fs';
|
||||
import { mkdir } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
@ -35,6 +37,7 @@ export interface S3DriverOptions extends S3ClientConfig {
|
||||
export class S3Driver implements StorageDriver {
|
||||
private s3Client: S3;
|
||||
private bucketName: string;
|
||||
private readonly logger = new Logger(S3Driver.name);
|
||||
|
||||
constructor(options: S3DriverOptions) {
|
||||
const { bucketName, region, endpoint, ...s3Options } = options;
|
||||
@ -69,6 +72,8 @@ export class S3Driver implements StorageDriver {
|
||||
|
||||
// @ts-expect-error legacy noImplicitAny
|
||||
private async emptyS3Directory(folderPath) {
|
||||
this.logger.log(`${folderPath} - emptying folder`);
|
||||
|
||||
const listParams = {
|
||||
Bucket: this.bucketName,
|
||||
Prefix: folderPath,
|
||||
@ -77,6 +82,13 @@ export class S3Driver implements StorageDriver {
|
||||
const listObjectsCommand = new ListObjectsV2Command(listParams);
|
||||
const listedObjects = await this.s3Client.send(listObjectsCommand);
|
||||
|
||||
this.logger.log(
|
||||
`${folderPath} - listed objects`,
|
||||
listedObjects.Contents,
|
||||
listedObjects.IsTruncated,
|
||||
listedObjects.Contents?.length,
|
||||
);
|
||||
|
||||
if (listedObjects.Contents?.length === 0) return;
|
||||
|
||||
const deleteParams = {
|
||||
@ -92,7 +104,11 @@ export class S3Driver implements StorageDriver {
|
||||
|
||||
await this.s3Client.send(deleteObjectCommand);
|
||||
|
||||
this.logger.log(`${folderPath} - objects deleted`);
|
||||
|
||||
if (listedObjects.IsTruncated) {
|
||||
this.logger.log(`${folderPath} - folder is truncated`);
|
||||
|
||||
await this.emptyS3Directory(folderPath);
|
||||
}
|
||||
}
|
||||
@ -101,6 +117,10 @@ export class S3Driver implements StorageDriver {
|
||||
folderPath: string;
|
||||
filename?: string;
|
||||
}): Promise<void> {
|
||||
this.logger.log(
|
||||
`${params.folderPath} - deleting file ${params.filename} from folder ${params.folderPath}`,
|
||||
);
|
||||
|
||||
if (params.filename) {
|
||||
const deleteCommand = new DeleteObjectCommand({
|
||||
Key: `${params.folderPath}/${params.filename}`,
|
||||
@ -110,6 +130,9 @@ export class S3Driver implements StorageDriver {
|
||||
await this.s3Client.send(deleteCommand);
|
||||
} else {
|
||||
await this.emptyS3Directory(params.folderPath);
|
||||
|
||||
this.logger.log(`${params.folderPath} - folder is empty`);
|
||||
|
||||
const deleteEmptyFolderCommand = new DeleteObjectCommand({
|
||||
Key: `${params.folderPath}`,
|
||||
Bucket: this.bucketName,
|
||||
|
||||
@ -18,8 +18,9 @@ export class FileWorkspaceFolderDeletionJob {
|
||||
try {
|
||||
await this.fileService.deleteWorkspaceFolder(workspaceId);
|
||||
} catch (error) {
|
||||
//todo: clean up error message once issue on workspace folder deletion is fixed + in s3 driver file
|
||||
throw new Error(
|
||||
`[${FileWorkspaceFolderDeletionJob.name}] Cannot delete workspace folder - ${workspaceId}`,
|
||||
`[${FileWorkspaceFolderDeletionJob.name}] Cannot delete workspace folder - ${workspaceId} - ${error?.message || error}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user