fix(growth): harden AI jobs and cost controls

This commit is contained in:
2026-08-21 01:48:47 +03:30
parent 86e9d7c5f9
commit a15c04cac1
13 changed files with 366 additions and 78 deletions

View File

@@ -23,22 +23,33 @@ import (
const maxExportBytes = 50 << 20
const (
defaultGrowthSSECapacity = 64
defaultGrowthSSEMaxDuration = 5 * time.Minute
defaultGrowthSSEPollInterval = 2 * time.Second
)
var defaultGrowthSSESlots = make(chan struct{}, defaultGrowthSSECapacity)
var errExportBytesExceeded = errors.New("export exceeds byte limit")
type Server struct {
identity *identity.Service
analytics *analytics.Service
growth growthReportService
logger *slog.Logger
frontendOrigin string
cookieSecure bool
identity *identity.Service
analytics *analytics.Service
growth growthReportService
logger *slog.Logger
frontendOrigin string
cookieSecure bool
growthSSESlots chan struct{}
growthSSEMaxDuration time.Duration
growthSSEPollInterval time.Duration
}
type sessionKey struct{}
type tokenKey struct{}
func NewServer(identityService *identity.Service, analyticsService *analytics.Service, logger *slog.Logger, frontendOrigin string, cookieSecure bool, growthService ...growthReportService) *Server {
server := &Server{identity: identityService, analytics: analyticsService, logger: logger, frontendOrigin: frontendOrigin, cookieSecure: cookieSecure}
server := &Server{identity: identityService, analytics: analyticsService, logger: logger, frontendOrigin: frontendOrigin, cookieSecure: cookieSecure, growthSSESlots: defaultGrowthSSESlots, growthSSEMaxDuration: defaultGrowthSSEMaxDuration, growthSSEPollInterval: defaultGrowthSSEPollInterval}
if len(growthService) > 0 {
server.growth = growthService[0]
}