Skip to content

Commit

Permalink
Merge pull request #1960 from slntopp/fix-cron
Browse files Browse the repository at this point in the history
Fix cron
  • Loading branch information
coddmeistr authored Jan 9, 2025
2 parents e06618e + cb0b6af commit 51c88ff
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/billing/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ func (s *BillingServiceServer) dailyCronJobAction(ctx context.Context, log *zap.
}()
// Jobs
s.InvoiceExpiringInstancesCronJob(ctx, log)
s.WhmcsInvoicesSyncerCronJob(ctx, log)
s.DeleteExpiredBalanceInvoicesCronJob(ctx, log)
s.NotifyToUpdateOvhPricesCronJob(ctx, log)
s.DeleteExpiredBalanceInvoicesCronJob(ctx, log)
s.WhmcsInvoicesSyncerCronJob(ctx, log)
}

func (s *BillingServiceServer) cronPreflightChecks(ctx context.Context, log *zap.Logger) error {
Expand Down
22 changes: 15 additions & 7 deletions pkg/billing/cron_whmcs_invoices_syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ func (s *BillingServiceServer) WhmcsInvoicesSyncerCronJob(ctx context.Context, l
}
log.Info("Size of NC invoices slice", zap.Any("bytes_count_for_invoice", reflect.TypeOf(graph.Invoice{}).Size()), zap.Int("len", len(ncInvoices)))

whmcsInvoices, err := s.whmcsGateway.GetInvoices(ctx)
if err != nil {
log.Error("Error listing whmcs invoices", zap.Error(err))
return
}
log.Info("Size of WHMCS invoices slice", zap.Any("bytes_count_for_invoice", reflect.TypeOf(whmcs_gateway.Invoice{}).Size()), zap.Int("len", len(whmcsInvoices)))
ids := make(map[int]struct{})
for _, val := range whmcsInvoices {
ids[int(val.Id)] = struct{}{}
}

delCount := 0
for _, inv := range ncInvoices {
if inv.Meta == nil {
Expand All @@ -34,7 +45,11 @@ func (s *BillingServiceServer) WhmcsInvoicesSyncerCronJob(ctx context.Context, l
if !ok {
continue
}
if _, ok = ids[int(whmcsId.GetNumberValue())]; ok {
continue
}
if _, err = s.whmcsGateway.GetInvoice(ctx, int(whmcsId.GetNumberValue())); err == nil {
log.Warn("Invoice found but wasn't presented in whmcs invoices list", zap.Int("id", int(whmcsId.GetNumberValue())))
continue
}
if !errors.Is(err, whmcs_gateway.ErrNotFound) {
Expand Down Expand Up @@ -66,13 +81,6 @@ func (s *BillingServiceServer) WhmcsInvoicesSyncerCronJob(ctx context.Context, l
}
}

whmcsInvoices, err := s.whmcsGateway.GetInvoices(ctx)
if err != nil {
log.Error("Error listing whmcs invoices", zap.Error(err))
return
}
log.Info("Size of WHMCS invoices slice", zap.Any("bytes_count_for_invoice", reflect.TypeOf(whmcs_gateway.Invoice{}).Size()), zap.Int("len", len(whmcsInvoices)))

ctx = context.WithValue(ctx, types.GatewayCallback, true) // Prevent whmcs event cycling
createdCount := 0
for _, whmcsInvoice := range whmcsInvoices {
Expand Down

0 comments on commit 51c88ff

Please sign in to comment.