MCPcopy Create free account
hub / github.com/PaperDebugger/paperdebugger / upsertUsage

Method upsertUsage

internal/services/usage.go:143–164  ·  view source on GitHub ↗
(ctx context.Context, collection *mongo.Collection, filter bson.M, cost float64, success bool, now time.Time)

Source from the content-addressed store, hash-verified

141}
142
143func (s *UsageService) upsertUsage(ctx context.Context, collection *mongo.Collection, filter bson.M, cost float64, success bool, now time.Time) error {
144 costField := "failed_cost"
145 if success {
146 costField = "success_cost"
147 }
148
149 update := bson.M{
150 "$inc": bson.M{
151 costField: cost,
152 },
153 "$set": bson.M{
154 "updated_at": bson.NewDateTimeFromTime(now),
155 },
156 "$setOnInsert": bson.M{
157 "_id": bson.NewObjectID(),
158 },
159 }
160
161 opts := options.UpdateOne().SetUpsert(true)
162 _, err := collection.UpdateOne(ctx, filter, update, opts)
163 return err
164}
165
166func (s *UsageService) trackHourlyUsage(ctx context.Context, userID bson.ObjectID, projectID string, cost float64, success bool, now time.Time) error {
167 filter := bson.M{

Callers 3

trackHourlyUsageMethod · 0.95
trackWeeklyUsageMethod · 0.95
trackLifetimeUsageMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected