@@ -8,15 +8,15 @@ import (
8
8
"context"
9
9
"encoding/json"
10
10
"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"
16
11
"io/ioutil"
17
12
"os"
18
13
"path/filepath"
19
14
"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"
20
20
)
21
21
22
22
type Reconciler interface {
@@ -30,12 +30,13 @@ func (f ReconcilerFunc) Reconcile() error {
30
30
}
31
31
32
32
type UsageReconciler struct {
33
- nowFunc func () time.Time
34
- conn * gorm.DB
33
+ nowFunc func () time.Time
34
+ conn * gorm.DB
35
+ billingController BillingController
35
36
}
36
37
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 }
39
40
}
40
41
41
42
type UsageReconcileStatus struct {
@@ -126,21 +127,11 @@ func (u *UsageReconciler) ReconcileTimeRange(ctx context.Context, from, to time.
126
127
}
127
128
status .Report = report
128
129
129
- submitUsageReport (status .Report )
130
+ u . billingController . SubmitUsageToStripe (status .Report )
130
131
131
132
return status , nil
132
133
}
133
134
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
-
144
135
func generateUsageReport (teams []teamWithWorkspaces , maxStopTime time.Time ) ([]TeamUsage , error ) {
145
136
var report []TeamUsage
146
137
for _ , team := range teams {
0 commit comments