From cbe062e605b64a004ae55bdf87a4271ab18bc36f Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Tue, 24 Sep 2024 14:48:58 +0530 Subject: [PATCH 1/4] fix trial end check --- admin/billing.go | 12 +++---- admin/database/database.go | 7 ++-- admin/database/postgres/postgres.go | 20 +++++++++-- admin/jobs/river/biller_event_handlers.go | 4 +-- .../river/payment_provider_event_handlers.go | 4 +-- admin/jobs/river/trial_checks.go | 33 ++++++++++++++++--- admin/server/billing.go | 6 ++-- 7 files changed, 62 insertions(+), 24 deletions(-) diff --git a/admin/billing.go b/admin/billing.go index 1d5f3e37752..0281958e90c 100644 --- a/admin/billing.go +++ b/admin/billing.go @@ -263,7 +263,7 @@ func (s *Service) RaiseNewOrgBillingIssues(ctx context.Context, orgID, subID, pl // CleanupTrialBillingIssues removes trial related billing issues and cancel associated jobs func (s *Service) CleanupTrialBillingIssues(ctx context.Context, orgID string) error { - bite, err := s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypeTrialEnded) + bite, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeTrialEnded) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing issue: %w", err) @@ -277,7 +277,7 @@ func (s *Service) CleanupTrialBillingIssues(ctx context.Context, orgID string) e } } - biot, err := s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypeOnTrial) + biot, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeOnTrial) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing issue: %w", err) @@ -296,7 +296,7 @@ func (s *Service) CleanupTrialBillingIssues(ctx context.Context, orgID string) e // CleanupBillingErrorSubCancellation removes subscription cancellation related billing error and cancel associated job func (s *Service) CleanupBillingErrorSubCancellation(ctx context.Context, orgID string) error { - bisc, err := s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypeSubscriptionCancelled) + bisc, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeSubscriptionCancelled) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing errors: %w", err) @@ -314,7 +314,7 @@ func (s *Service) CleanupBillingErrorSubCancellation(ctx context.Context, orgID } func (s *Service) CheckBillingErrors(ctx context.Context, orgID string) error { - be, err := s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypeTrialEnded) + be, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeTrialEnded) if err != nil { if !errors.Is(err, database.ErrNotFound) { return err @@ -325,7 +325,7 @@ func (s *Service) CheckBillingErrors(ctx context.Context, orgID string) error { return fmt.Errorf("trial has ended") } - be, err = s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypePaymentFailed) + be, err = s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypePaymentFailed) if err != nil { if !errors.Is(err, database.ErrNotFound) { return err @@ -336,7 +336,7 @@ func (s *Service) CheckBillingErrors(ctx context.Context, orgID string) error { return fmt.Errorf("invoice payment failed") } - be, err = s.DB.FindBillingIssueByType(ctx, orgID, database.BillingIssueTypeSubscriptionCancelled) + be, err = s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeSubscriptionCancelled) if err != nil { if !errors.Is(err, database.ErrNotFound) { return err diff --git a/admin/database/database.go b/admin/database/database.go index 79ab2d71721..0fa96bdef7b 100644 --- a/admin/database/database.go +++ b/admin/database/database.go @@ -266,14 +266,15 @@ type DB interface { FindOrganizationForPaymentCustomerID(ctx context.Context, customerID string) (*Organization, error) FindOrganizationForBillingCustomerID(ctx context.Context, customerID string) (*Organization, error) - FindBillingIssues(ctx context.Context, orgID string) ([]*BillingIssue, error) - FindBillingIssueByType(ctx context.Context, orgID string, errorType BillingIssueType) (*BillingIssue, error) + FindBillingIssuesForOrg(ctx context.Context, orgID string) ([]*BillingIssue, error) + FindBillingIssueByTypeForOrg(ctx context.Context, orgID string, errorType BillingIssueType) (*BillingIssue, error) + FindBillingIssueByType(ctx context.Context, errorType BillingIssueType) ([]*BillingIssue, error) FindBillingIssueByTypeNotOverdueProcessed(ctx context.Context, errorType BillingIssueType) ([]*BillingIssue, error) FindBillingIssueByTypeNotOverdueProcessedForOrg(ctx context.Context, orgID string, errorType BillingIssueType) (*BillingIssue, error) UpsertBillingIssue(ctx context.Context, opts *UpsertBillingIssueOptions) (*BillingIssue, error) UpdateBillingIssueOverdueAsProcessed(ctx context.Context, id string) error DeleteBillingIssue(ctx context.Context, id string) error - DeleteBillingIssueByType(ctx context.Context, orgID string, errorType BillingIssueType) error + DeleteBillingIssueByTypeForOrg(ctx context.Context, orgID string, errorType BillingIssueType) error } // Tx represents a database transaction. It can only be used to commit and rollback transactions. diff --git a/admin/database/postgres/postgres.go b/admin/database/postgres/postgres.go index 46ab81ba3bc..55f36441861 100644 --- a/admin/database/postgres/postgres.go +++ b/admin/database/postgres/postgres.go @@ -1948,7 +1948,7 @@ func (c *connection) FindOrganizationForBillingCustomerID(ctx context.Context, c return res, nil } -func (c *connection) FindBillingIssues(ctx context.Context, orgID string) ([]*database.BillingIssue, error) { +func (c *connection) FindBillingIssuesForOrg(ctx context.Context, orgID string) ([]*database.BillingIssue, error) { var res []*billingIssueDTO err := c.db.SelectContext(ctx, &res, `SELECT * FROM billing_issues WHERE org_id = $1`, orgID) if err != nil { @@ -1962,7 +1962,7 @@ func (c *connection) FindBillingIssues(ctx context.Context, orgID string) ([]*da return billingErrors, nil } -func (c *connection) FindBillingIssueByType(ctx context.Context, orgID string, errorType database.BillingIssueType) (*database.BillingIssue, error) { +func (c *connection) FindBillingIssueByTypeForOrg(ctx context.Context, orgID string, errorType database.BillingIssueType) (*database.BillingIssue, error) { res := &billingIssueDTO{} err := c.db.GetContext(ctx, res, `SELECT * FROM billing_issues WHERE org_id = $1 AND type = $2`, orgID, errorType) if err != nil { @@ -1971,6 +1971,20 @@ func (c *connection) FindBillingIssueByType(ctx context.Context, orgID string, e return res.AsModel(), nil } +func (c *connection) FindBillingIssueByType(ctx context.Context, errorType database.BillingIssueType) ([]*database.BillingIssue, error) { + var res []*billingIssueDTO + err := c.db.SelectContext(ctx, &res, `SELECT * FROM billing_issues WHERE type = $1`, errorType) + if err != nil { + return nil, parseErr("billing issues", err) + } + + var billingErrors []*database.BillingIssue + for _, dto := range res { + billingErrors = append(billingErrors, dto.AsModel()) + } + return billingErrors, nil +} + func (c *connection) FindBillingIssueByTypeNotOverdueProcessed(ctx context.Context, errorType database.BillingIssueType) ([]*database.BillingIssue, error) { var res []*billingIssueDTO err := c.db.SelectContext(ctx, &res, `SELECT * FROM billing_issues WHERE type = $1 AND overdue_processed = false`, errorType) @@ -2032,7 +2046,7 @@ func (c *connection) DeleteBillingIssue(ctx context.Context, id string) error { return checkDeleteRow("billing issue", res, err) } -func (c *connection) DeleteBillingIssueByType(ctx context.Context, orgID string, errorType database.BillingIssueType) error { +func (c *connection) DeleteBillingIssueByTypeForOrg(ctx context.Context, orgID string, errorType database.BillingIssueType) error { res, err := c.getDB(ctx).ExecContext(ctx, "DELETE FROM billing_issues WHERE org_id = $1 AND type = $2", orgID, errorType) return checkDeleteRow("billing issue", res, err) } diff --git a/admin/jobs/river/biller_event_handlers.go b/admin/jobs/river/biller_event_handlers.go index b8688df90ec..ae9f697eb75 100644 --- a/admin/jobs/river/biller_event_handlers.go +++ b/admin/jobs/river/biller_event_handlers.go @@ -42,7 +42,7 @@ func (w *PaymentFailedWorker) Work(ctx context.Context, job *river.Job[PaymentFa return fmt.Errorf("failed to find organization of billing customer id %q: %w", job.Args.BillingCustomerID, err) } - be, err := w.admin.DB.FindBillingIssueByType(ctx, org.ID, database.BillingIssueTypePaymentFailed) + be, err := w.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypePaymentFailed) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing errors: %w", err) @@ -120,7 +120,7 @@ func (w *PaymentSuccessWorker) Work(ctx context.Context, job *river.Job[PaymentS } // check for existing billing error and delete it - be, err := w.admin.DB.FindBillingIssueByType(ctx, org.ID, database.BillingIssueTypePaymentFailed) + be, err := w.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypePaymentFailed) if err != nil { if errors.Is(err, database.ErrNotFound) { // no billing error, ignore diff --git a/admin/jobs/river/payment_provider_event_handlers.go b/admin/jobs/river/payment_provider_event_handlers.go index a41a9655fcc..feb5b29e273 100644 --- a/admin/jobs/river/payment_provider_event_handlers.go +++ b/admin/jobs/river/payment_provider_event_handlers.go @@ -36,7 +36,7 @@ func (w *PaymentMethodAddedWorker) Work(ctx context.Context, job *river.Job[Paym } // check for no payment method billing error - be, err := w.admin.DB.FindBillingIssueByType(ctx, org.ID, database.BillingIssueTypeNoPaymentMethod) + be, err := w.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypeNoPaymentMethod) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing errors: %w", err) @@ -128,7 +128,7 @@ func (w *CustomerAddressUpdatedWorker) Work(ctx context.Context, job *river.Job[ } // look for no billable address billing error and remove it - be, err := w.admin.DB.FindBillingIssueByType(ctx, org.ID, database.BillingIssueTypeNoBillableAddress) + be, err := w.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypeNoBillableAddress) if err != nil { if !errors.Is(err, database.ErrNotFound) { return fmt.Errorf("failed to find billing errors: %w", err) diff --git a/admin/jobs/river/trial_checks.go b/admin/jobs/river/trial_checks.go index b211ea6353a..05a248e73fc 100644 --- a/admin/jobs/river/trial_checks.go +++ b/admin/jobs/river/trial_checks.go @@ -89,7 +89,7 @@ func (w *TrialEndCheckWorker) Work(ctx context.Context, job *river.Job[TrialEndC } func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { - onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeOnTrial) + onTrialOrgs, err := w.admin.DB.FindBillingIssueByType(ctx, database.BillingIssueTypeOnTrial) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing issue @@ -114,7 +114,13 @@ func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { w.logger.Warn("trial period has ended", zap.String("org_id", org.ID), zap.String("org_name", org.Name)) gracePeriodEndDate := m.EndDate.AddDate(0, 0, gracePeriodDays) - _, err = w.admin.DB.UpsertBillingIssue(ctx, &database.UpsertBillingIssueOptions{ + + cctx, tx, err := w.admin.DB.NewTx(ctx) + if err != nil { + return fmt.Errorf("failed to start transaction: %w", err) + } + + _, err = w.admin.DB.UpsertBillingIssue(cctx, &database.UpsertBillingIssueOptions{ OrgID: org.ID, Type: database.BillingIssueTypeTrialEnded, Metadata: &database.BillingIssueMetadataTrialEnded{ @@ -123,9 +129,23 @@ func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { EventTime: m.EndDate.AddDate(0, 0, 1), }) if err != nil { + err = tx.Rollback() + if err != nil { + return fmt.Errorf("failed to rollback transaction: %w", err) + } return fmt.Errorf("failed to add billing error: %w", err) } + // delete the on-trial billing issue + err = w.admin.DB.DeleteBillingIssue(cctx, o.ID) + if err != nil { + err = tx.Rollback() + if err != nil { + return fmt.Errorf("failed to rollback transaction: %w", err) + } + return fmt.Errorf("failed to delete billing issue: %w", err) + } + // send email err = w.admin.Email.SendTrialEnded(&email.TrialEnded{ ToEmail: org.BillingEmail, @@ -134,13 +154,16 @@ func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { GracePeriodEndDate: gracePeriodEndDate, }) if err != nil { + err = tx.Rollback() + if err != nil { + return fmt.Errorf("failed to rollback transaction: %w", err) + } return fmt.Errorf("failed to send trial period ended email for org %q: %w", org.Name, err) } - // mark the billing issue as processed - err = w.admin.DB.UpdateBillingIssueOverdueAsProcessed(ctx, o.ID) + err = tx.Commit() if err != nil { - return fmt.Errorf("failed to update billing issue as processed: %w", err) + return fmt.Errorf("failed to commit transaction: %w", err) } } diff --git a/admin/server/billing.go b/admin/server/billing.go index 3c4c7cb1817..208a1bd7eb0 100644 --- a/admin/server/billing.go +++ b/admin/server/billing.go @@ -114,7 +114,7 @@ func (s *Server) UpdateBillingSubscription(ctx context.Context, req *adminv1.Upd validationErrs = append(validationErrs, "no billing address found, click on update information to add billing address") } - be, err := s.admin.DB.FindBillingIssueByType(ctx, org.ID, database.BillingIssueTypePaymentFailed) + be, err := s.admin.DB.FindBillingIssueByTypeForOrg(ctx, org.ID, database.BillingIssueTypePaymentFailed) if err != nil { if !errors.Is(err, database.ErrNotFound) { return nil, status.Error(codes.Internal, err.Error()) @@ -407,7 +407,7 @@ func (s *Server) ListOrganizationBillingIssues(ctx context.Context, req *adminv1 return nil, status.Error(codes.PermissionDenied, "not allowed to read org billing errors") } - issues, err := s.admin.DB.FindBillingIssues(ctx, org.ID) + issues, err := s.admin.DB.FindBillingIssuesForOrg(ctx, org.ID) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } @@ -447,7 +447,7 @@ func (s *Server) SudoDeleteOrganizationBillingIssue(ctx context.Context, req *ad return nil, err } - err = s.admin.DB.DeleteBillingIssueByType(ctx, org.ID, t) + err = s.admin.DB.DeleteBillingIssueByTypeForOrg(ctx, org.ID, t) if err != nil { return nil, status.Error(codes.Internal, err.Error()) } From 7017bcc06f9005bb285d2779b3bbcce8f9e30212 Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Tue, 24 Sep 2024 15:35:20 +0530 Subject: [PATCH 2/4] comment --- admin/billing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/billing.go b/admin/billing.go index 0281958e90c..8cc8696ed3e 100644 --- a/admin/billing.go +++ b/admin/billing.go @@ -294,7 +294,7 @@ func (s *Service) CleanupTrialBillingIssues(ctx context.Context, orgID string) e return nil } -// CleanupBillingErrorSubCancellation removes subscription cancellation related billing error and cancel associated job +// CleanupBillingErrorSubCancellation removes subscription cancellation related billing error func (s *Service) CleanupBillingErrorSubCancellation(ctx context.Context, orgID string) error { bisc, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeSubscriptionCancelled) if err != nil { From 4b38bde58112642d460cf73c59c0fc540939f09d Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Wed, 25 Sep 2024 20:36:46 +0530 Subject: [PATCH 3/4] trial end check optimization --- admin/database/database.go | 3 +-- admin/database/postgres/postgres.go | 13 ++----------- admin/jobs/river/biller_event_handlers.go | 2 +- admin/jobs/river/subscription_handlers.go | 2 +- admin/jobs/river/trial_checks.go | 6 +++--- 5 files changed, 8 insertions(+), 18 deletions(-) diff --git a/admin/database/database.go b/admin/database/database.go index 0fa96bdef7b..2daad2062be 100644 --- a/admin/database/database.go +++ b/admin/database/database.go @@ -269,8 +269,7 @@ type DB interface { FindBillingIssuesForOrg(ctx context.Context, orgID string) ([]*BillingIssue, error) FindBillingIssueByTypeForOrg(ctx context.Context, orgID string, errorType BillingIssueType) (*BillingIssue, error) FindBillingIssueByType(ctx context.Context, errorType BillingIssueType) ([]*BillingIssue, error) - FindBillingIssueByTypeNotOverdueProcessed(ctx context.Context, errorType BillingIssueType) ([]*BillingIssue, error) - FindBillingIssueByTypeNotOverdueProcessedForOrg(ctx context.Context, orgID string, errorType BillingIssueType) (*BillingIssue, error) + FindBillingIssueByTypeAndOverdueProcessed(ctx context.Context, errorType BillingIssueType, overdueProcessed bool) ([]*BillingIssue, error) UpsertBillingIssue(ctx context.Context, opts *UpsertBillingIssueOptions) (*BillingIssue, error) UpdateBillingIssueOverdueAsProcessed(ctx context.Context, id string) error DeleteBillingIssue(ctx context.Context, id string) error diff --git a/admin/database/postgres/postgres.go b/admin/database/postgres/postgres.go index 55f36441861..0fbcbf15cf6 100644 --- a/admin/database/postgres/postgres.go +++ b/admin/database/postgres/postgres.go @@ -1985,9 +1985,9 @@ func (c *connection) FindBillingIssueByType(ctx context.Context, errorType datab return billingErrors, nil } -func (c *connection) FindBillingIssueByTypeNotOverdueProcessed(ctx context.Context, errorType database.BillingIssueType) ([]*database.BillingIssue, error) { +func (c *connection) FindBillingIssueByTypeAndOverdueProcessed(ctx context.Context, errorType database.BillingIssueType, overdueProcessed bool) ([]*database.BillingIssue, error) { var res []*billingIssueDTO - err := c.db.SelectContext(ctx, &res, `SELECT * FROM billing_issues WHERE type = $1 AND overdue_processed = false`, errorType) + err := c.db.SelectContext(ctx, &res, `SELECT * FROM billing_issues WHERE type = $1 AND overdue_processed = $2`, errorType, overdueProcessed) if err != nil { return nil, parseErr("billing issues", err) } @@ -1999,15 +1999,6 @@ func (c *connection) FindBillingIssueByTypeNotOverdueProcessed(ctx context.Conte return billingErrors, nil } -func (c *connection) FindBillingIssueByTypeNotOverdueProcessedForOrg(ctx context.Context, orgID string, errorType database.BillingIssueType) (*database.BillingIssue, error) { - res := &billingIssueDTO{} - err := c.db.GetContext(ctx, res, `SELECT * FROM billing_issues WHERE org_id = $1 AND type = $2 AND overdue_processed = false`, orgID, errorType) - if err != nil { - return nil, parseErr("billing issue", err) - } - return res.AsModel(), nil -} - func (c *connection) UpsertBillingIssue(ctx context.Context, opts *database.UpsertBillingIssueOptions) (*database.BillingIssue, error) { if err := database.Validate(opts); err != nil { return nil, err diff --git a/admin/jobs/river/biller_event_handlers.go b/admin/jobs/river/biller_event_handlers.go index ae9f697eb75..16f45b188ef 100644 --- a/admin/jobs/river/biller_event_handlers.go +++ b/admin/jobs/river/biller_event_handlers.go @@ -191,7 +191,7 @@ func (w *PaymentFailedGracePeriodCheckWorker) Work(ctx context.Context, job *riv } func (w *PaymentFailedGracePeriodCheckWorker) paymentFailedGracePeriodCheck(ctx context.Context) error { - failures, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypePaymentFailed) + failures, err := w.admin.DB.FindBillingIssueByTypeAndOverdueProcessed(ctx, database.BillingIssueTypePaymentFailed, false) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing error diff --git a/admin/jobs/river/subscription_handlers.go b/admin/jobs/river/subscription_handlers.go index c8e15f38593..b8a8d079feb 100644 --- a/admin/jobs/river/subscription_handlers.go +++ b/admin/jobs/river/subscription_handlers.go @@ -127,7 +127,7 @@ func (w *SubscriptionCancellationCheckWorker) Work(ctx context.Context, job *riv } func (w *SubscriptionCancellationCheckWorker) subscriptionCancellationCheck(ctx context.Context) error { - cancelled, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeSubscriptionCancelled) + cancelled, err := w.admin.DB.FindBillingIssueByTypeAndOverdueProcessed(ctx, database.BillingIssueTypeSubscriptionCancelled, false) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing issue diff --git a/admin/jobs/river/trial_checks.go b/admin/jobs/river/trial_checks.go index 05a248e73fc..1a226b086a5 100644 --- a/admin/jobs/river/trial_checks.go +++ b/admin/jobs/river/trial_checks.go @@ -30,7 +30,7 @@ func (w *TrialEndingSoonWorker) Work(ctx context.Context, job *river.Job[TrialEn } func (w *TrialEndingSoonWorker) trialEndingSoon(ctx context.Context) error { - onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeOnTrial) + onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeAndOverdueProcessed(ctx, database.BillingIssueTypeOnTrial, false) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing issue @@ -89,7 +89,7 @@ func (w *TrialEndCheckWorker) Work(ctx context.Context, job *river.Job[TrialEndC } func (w *TrialEndCheckWorker) trialEndCheck(ctx context.Context) error { - onTrialOrgs, err := w.admin.DB.FindBillingIssueByType(ctx, database.BillingIssueTypeOnTrial) + onTrialOrgs, err := w.admin.DB.FindBillingIssueByTypeAndOverdueProcessed(ctx, database.BillingIssueTypeOnTrial, true) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing issue @@ -185,7 +185,7 @@ func (w *TrialGracePeriodCheckWorker) Work(ctx context.Context, job *river.Job[T } func (w *TrialGracePeriodCheckWorker) trialGracePeriodCheck(ctx context.Context) error { - trailEndedOrgs, err := w.admin.DB.FindBillingIssueByTypeNotOverdueProcessed(ctx, database.BillingIssueTypeTrialEnded) + trailEndedOrgs, err := w.admin.DB.FindBillingIssueByTypeAndOverdueProcessed(ctx, database.BillingIssueTypeTrialEnded, false) if err != nil { if errors.Is(err, database.ErrNotFound) { // no orgs have this billing issue From a967dd11c841b87d3342b42018f3debae7d9ae6d Mon Sep 17 00:00:00 2001 From: Parag Jain Date: Wed, 25 Sep 2024 20:39:35 +0530 Subject: [PATCH 4/4] comment --- admin/billing.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/billing.go b/admin/billing.go index 8cc8696ed3e..d7f99d5d74c 100644 --- a/admin/billing.go +++ b/admin/billing.go @@ -261,7 +261,7 @@ func (s *Service) RaiseNewOrgBillingIssues(ctx context.Context, orgID, subID, pl return nil } -// CleanupTrialBillingIssues removes trial related billing issues and cancel associated jobs +// CleanupTrialBillingIssues removes trial related billing issues func (s *Service) CleanupTrialBillingIssues(ctx context.Context, orgID string) error { bite, err := s.DB.FindBillingIssueByTypeForOrg(ctx, orgID, database.BillingIssueTypeTrialEnded) if err != nil {