Skip to content

Commit

Permalink
cleaning workspace job - fix on soft delete condition (#10380)
Browse files Browse the repository at this point in the history
Context
If the command runs multiple times, soft deleted workspaces are soft
deleted again (+ email spamming)

Solution
Check for soft deletion before entering soft delete condition
  • Loading branch information
etiennejouan authored Feb 21, 2025
1 parent 29d079b commit 5863c45
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { UserService } from 'src/engine/core-modules/user/services/user.service'
import { UserVarsService } from 'src/engine/core-modules/user/user-vars/services/user-vars.service';
import { WorkspaceService } from 'src/engine/core-modules/workspace/services/workspace.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { USER_WORKSPACE_DELETION_WARNING_SENT_KEY } from 'src/engine/workspace-manager/workspace-cleaner/constants/user-workspace-deletion-warning-sent-key.constant';
import {
WorkspaceCleanerException,
Expand All @@ -42,6 +43,7 @@ export class CleanerWorkspaceService {
private readonly workspaceRepository: Repository<Workspace>,
@InjectRepository(BillingSubscription, 'core')
private readonly billingSubscriptionRepository: Repository<BillingSubscription>,
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
) {
this.inactiveDaysBeforeSoftDelete = this.environmentService.get(
'WORKSPACE_INACTIVE_DAYS_BEFORE_SOFT_DELETION',
Expand Down Expand Up @@ -291,7 +293,10 @@ export class CleanerWorkspaceService {

continue;
}
if (workspaceInactivity > this.inactiveDaysBeforeSoftDelete) {
if (
workspaceInactivity > this.inactiveDaysBeforeSoftDelete &&
!isDefined(workspace.deletedAt)
) {
await this.informWorkspaceMembersAndSoftDeleteWorkspace(
workspace,
workspaceInactivity,
Expand All @@ -315,6 +320,10 @@ export class CleanerWorkspaceService {
`Error while processing workspace ${workspace.id} ${workspace.displayName}: ${error}`,
);
}

await this.twentyORMGlobalManager.destroyDataSourceForWorkspace(
workspace.id,
);
}
this.logger.log(
`${dryRun ? 'DRY RUN - ' : ''}batchWarnOrCleanSuspendedWorkspaces done!`,
Expand Down

0 comments on commit 5863c45

Please sign in to comment.