Update cleaning suspended workspace job (#9999)

- split workspace metadata deletion into multiple queries
- delete all subscriptions when workspace is deleted

---------

Co-authored-by: etiennejouan <jouan.etienne@gmail.com>
This commit is contained in:
Etienne
2025-02-04 15:49:22 +01:00
committed by GitHub
parent dfc1bb7c29
commit cc14c7e0d0
4 changed files with 22 additions and 3 deletions

View File

@ -106,7 +106,7 @@ export class BillingSubscriptionService {
return billingSubscriptionItem;
}
async deleteSubscription(workspaceId: string) {
async deleteSubscriptions(workspaceId: string) {
const subscriptionToCancel =
await this.getCurrentBillingSubscriptionOrThrow({
workspaceId,
@ -116,8 +116,8 @@ export class BillingSubscriptionService {
await this.stripeSubscriptionService.cancelSubscription(
subscriptionToCancel.stripeSubscriptionId,
);
await this.billingSubscriptionRepository.delete(subscriptionToCancel.id);
}
await this.billingSubscriptionRepository.delete({ workspaceId });
}
async handleUnpaidInvoices(data: Stripe.SetupIntentSucceededEvent.Data) {

View File

@ -184,7 +184,7 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
await this.userWorkspaceRepository.delete({ workspaceId: id });
if (this.billingService.isBillingEnabled()) {
await this.billingSubscriptionService.deleteSubscription(workspace.id);
await this.billingSubscriptionService.deleteSubscriptions(workspace.id);
}
await this.workspaceManagerService.delete(id);