chore: build
ci-api / test (push) Successful in 26m18s

This commit is contained in:
Xor290
2026-08-18 16:37:00 +02:00
parent 955f2325fb
commit aa1aa60f00
8 changed files with 189 additions and 4 deletions
@@ -1,6 +1,7 @@
package demos
import (
"context"
"errors"
"log"
"strings"
@@ -282,6 +283,45 @@ func (s *Service) Extend(id string) (Demo, error) {
return s.store.Update(d)
}
// RunExpirationLoop détruit automatiquement les démos dont le TTL est
// dépassé, à intervalle régulier — jusqu'ici rien n'appelait Delete() sur
// une démo expirée, le compte à rebours affiché en interface n'avait aucun
// effet réel. À lancer une fois dans une goroutine au démarrage de l'API
// (voir cmd/api/main.go), s'arrête proprement quand ctx est annulé (extinction).
// Les démos premium n'expirent jamais en pratique (voir TransferToPaid,
// ExpiresAt repoussé de 10 ans) : jamais concernées ici.
func (s *Service) RunExpirationLoop(ctx context.Context, interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
s.expireOverdueDemos()
}
}
}
func (s *Service) expireOverdueDemos() {
all, err := s.store.List()
if err != nil {
log.Printf("expiration: liste des démos échouée: %v", err)
return
}
now := s.now().UTC()
for _, d := range all {
if !d.Status.Active() || !d.ExpiresAt.Before(now) {
continue
}
if _, err := s.Delete(d.ID); err != nil {
log.Printf("expiration: destruction de %s (TTL dépassé) échouée: %v", d.Namespace, err)
continue
}
log.Printf("expiration: démo %s détruite (TTL dépassé)", d.Namespace)
}
}
// shortID : 8 premiers caractères hex d'un uuid pour un nom de namespace court.
func shortID(id string) string {
clean := ""