fix no billing subscription error (#11257)
closes https://github.com/twentyhq/core-team-issues/issues/625 Context : Soft-deleted workspaces no longer have any subscriptions. Computing inactivity causes an error.
This commit is contained in:
@ -319,11 +319,13 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
softDelete,
|
||||
);
|
||||
}
|
||||
this.logger.log(`workspace ${id} user workspaces deleted`);
|
||||
|
||||
await this.workspaceCacheStorageService.flush(
|
||||
workspace.id,
|
||||
workspace.metadataVersion,
|
||||
);
|
||||
this.logger.log(`workspace ${id} cache flushed`);
|
||||
|
||||
if (softDelete) {
|
||||
if (this.billingService.isBillingEnabled()) {
|
||||
@ -348,6 +350,7 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
await this.customDomainService.deleteCustomHostnameByHostnameSilently(
|
||||
workspace.customDomain,
|
||||
);
|
||||
this.logger.log(`workspace ${id} custom domain deleted`);
|
||||
}
|
||||
|
||||
await this.workspaceRepository.delete(id);
|
||||
|
||||
@ -326,32 +326,35 @@ export class CleanerWorkspaceService {
|
||||
|
||||
for (const workspace of workspaces) {
|
||||
try {
|
||||
const isSoftDeletedWorkspace = isDefined(workspace.deletedAt);
|
||||
|
||||
if (isSoftDeletedWorkspace) {
|
||||
const daysSinceSoftDeleted = workspace.deletedAt
|
||||
? differenceInDays(new Date(), workspace.deletedAt)
|
||||
: 0;
|
||||
|
||||
if (
|
||||
daysSinceSoftDeleted >
|
||||
this.inactiveDaysBeforeDelete -
|
||||
this.inactiveDaysBeforeSoftDelete &&
|
||||
deletedWorkspacesCount <
|
||||
this.maxNumberOfWorkspacesDeletedPerExecution
|
||||
) {
|
||||
this.logger.log(
|
||||
`${dryRun ? 'DRY RUN - ' : ''}Destroying workspace ${workspace.id} ${workspace.displayName}`,
|
||||
);
|
||||
if (!dryRun) {
|
||||
await this.workspaceService.deleteWorkspace(workspace.id);
|
||||
}
|
||||
deletedWorkspacesCount++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
const workspaceInactivity =
|
||||
await this.computeWorkspaceBillingInactivity(workspace);
|
||||
|
||||
const daysSinceSoftDeleted = workspace.deletedAt
|
||||
? differenceInDays(new Date(), workspace.deletedAt)
|
||||
: 0;
|
||||
|
||||
if (
|
||||
daysSinceSoftDeleted >
|
||||
this.inactiveDaysBeforeDelete - this.inactiveDaysBeforeSoftDelete &&
|
||||
deletedWorkspacesCount < this.maxNumberOfWorkspacesDeletedPerExecution
|
||||
) {
|
||||
this.logger.log(
|
||||
`${dryRun ? 'DRY RUN - ' : ''}Destroying workspace ${workspace.id} ${workspace.displayName}`,
|
||||
);
|
||||
if (!dryRun) {
|
||||
await this.workspaceService.deleteWorkspace(workspace.id);
|
||||
}
|
||||
deletedWorkspacesCount++;
|
||||
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
workspaceInactivity > this.inactiveDaysBeforeSoftDelete &&
|
||||
!isDefined(workspace.deletedAt)
|
||||
) {
|
||||
if (workspaceInactivity > this.inactiveDaysBeforeSoftDelete) {
|
||||
await this.informWorkspaceMembersAndSoftDeleteWorkspace(
|
||||
workspace,
|
||||
workspaceInactivity,
|
||||
|
||||
Reference in New Issue
Block a user