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,
|
softDelete,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
this.logger.log(`workspace ${id} user workspaces deleted`);
|
||||||
|
|
||||||
await this.workspaceCacheStorageService.flush(
|
await this.workspaceCacheStorageService.flush(
|
||||||
workspace.id,
|
workspace.id,
|
||||||
workspace.metadataVersion,
|
workspace.metadataVersion,
|
||||||
);
|
);
|
||||||
|
this.logger.log(`workspace ${id} cache flushed`);
|
||||||
|
|
||||||
if (softDelete) {
|
if (softDelete) {
|
||||||
if (this.billingService.isBillingEnabled()) {
|
if (this.billingService.isBillingEnabled()) {
|
||||||
@ -348,6 +350,7 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
|||||||
await this.customDomainService.deleteCustomHostnameByHostnameSilently(
|
await this.customDomainService.deleteCustomHostnameByHostnameSilently(
|
||||||
workspace.customDomain,
|
workspace.customDomain,
|
||||||
);
|
);
|
||||||
|
this.logger.log(`workspace ${id} custom domain deleted`);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.workspaceRepository.delete(id);
|
await this.workspaceRepository.delete(id);
|
||||||
|
|||||||
@ -326,32 +326,35 @@ export class CleanerWorkspaceService {
|
|||||||
|
|
||||||
for (const workspace of workspaces) {
|
for (const workspace of workspaces) {
|
||||||
try {
|
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 =
|
const workspaceInactivity =
|
||||||
await this.computeWorkspaceBillingInactivity(workspace);
|
await this.computeWorkspaceBillingInactivity(workspace);
|
||||||
|
|
||||||
const daysSinceSoftDeleted = workspace.deletedAt
|
if (workspaceInactivity > this.inactiveDaysBeforeSoftDelete) {
|
||||||
? 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)
|
|
||||||
) {
|
|
||||||
await this.informWorkspaceMembersAndSoftDeleteWorkspace(
|
await this.informWorkspaceMembersAndSoftDeleteWorkspace(
|
||||||
workspace,
|
workspace,
|
||||||
workspaceInactivity,
|
workspaceInactivity,
|
||||||
|
|||||||
Reference in New Issue
Block a user