@@ -8,15 +8,15 @@ import (
88 "context"
99 "encoding/json"
1010 "fmt"
11- "github.com/gitpod-io/gitpod/common-go/log"
12- "github.com/gitpod-io/gitpod/usage/pkg/db"
13- "github.com/gitpod-io/gitpod/usage/pkg/stripe"
14- "github.com/google/uuid"
15- "gorm.io/gorm"
1611 "io/ioutil"
1712 "os"
1813 "path/filepath"
1914 "time"
15+
16+ "github.com/gitpod-io/gitpod/common-go/log"
17+ "github.com/gitpod-io/gitpod/usage/pkg/db"
18+ "github.com/google/uuid"
19+ "gorm.io/gorm"
2020)
2121
2222type Reconciler interface {
@@ -30,12 +30,13 @@ func (f ReconcilerFunc) Reconcile() error {
3030}
3131
3232type UsageReconciler struct {
33- nowFunc func () time.Time
34- conn * gorm.DB
33+ nowFunc func () time.Time
34+ conn * gorm.DB
35+ billingController BillingController
3536}
3637
37- func NewUsageReconciler (conn * gorm.DB ) * UsageReconciler {
38- return & UsageReconciler {conn : conn , nowFunc : time .Now }
38+ func NewUsageReconciler (conn * gorm.DB , billingController BillingController ) * UsageReconciler {
39+ return & UsageReconciler {conn : conn , billingController : billingController , nowFunc : time .Now }
3940}
4041
4142type UsageReconcileStatus struct {
@@ -126,21 +127,11 @@ func (u *UsageReconciler) ReconcileTimeRange(ctx context.Context, from, to time.
126127 }
127128 status .Report = report
128129
129- submitUsageReport (status .Report )
130+ u . billingController . SubmitUsageToStripe (status .Report )
130131
131132 return status , nil
132133}
133134
134- func submitUsageReport (report []TeamUsage ) {
135- // Convert the usage report to sum all entries for the same team.
136- var summedReport = make (map [string ]int64 )
137- for _ , usageEntry := range report {
138- summedReport [usageEntry .TeamID ] += usageEntry .WorkspaceSeconds
139- }
140-
141- stripe .UpdateUsage (summedReport )
142- }
143-
144135func generateUsageReport (teams []teamWithWorkspaces , maxStopTime time.Time ) ([]TeamUsage , error ) {
145136 var report []TeamUsage
146137 for _ , team := range teams {
0 commit comments