Files
pages/internal/server/gc_worker.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

86 lines
1.7 KiB
Go

package server
import (
"context"
"fmt"
"log"
"math"
"os"
"strconv"
"strings"
"time"
"pageswiki/internal/store"
)
// This is deliberately not exposed as a user-editable EventDefinition type.
// Instance maintenance retains the previous grace period (at least 24h), even
// after Domain config changes or a restart. Only the operator environment can
// explicitly increase the persistent retention high-water mark.
func (s *Server) zombieMaintenanceGrace() (int64, error) {
raw, err := s.store.GetConfig("zombie_grace_hours")
if err != nil {
return 0, err // Never shorten retention on a failed legacy config read.
}
grace := store.ZombieGCDefaultGraceSeconds
if hours, err := strconv.ParseInt(raw, 10, 64); err == nil && hours > 0 {
if hours > math.MaxInt64/3600 {
grace = math.MaxInt64
} else {
grace = max(grace, hours*3600)
}
}
if raw := strings.TrimSpace(os.Getenv("PAGESWIKI_ZOMBIE_GC_GRACE_HOURS")); raw != "" {
hours, err := strconv.ParseInt(raw, 10, 64)
if err != nil || hours < 0 || hours > math.MaxInt64/3600 {
return 0, fmt.Errorf("invalid PAGESWIKI_ZOMBIE_GC_GRACE_HOURS")
}
grace = max(grace, hours*3600)
}
return s.store.RaiseZombieMaintenanceGrace(context.Background(), grace)
}
func (s *Server) startGCWorker() {
grace, err := s.zombieMaintenanceGrace()
if err != nil {
log.Printf("zombie GC maintenance disabled: %v", err)
return
}
go func() {
ticker :=
time.NewTicker(
6 * time.Hour,
)
defer ticker.Stop()
for {
<-ticker.C
deleted, err :=
s.store.PurgeZombieObjects(
grace,
100,
)
if err != nil {
log.Printf(
"zombie gc error: %v",
err,
)
} else if deleted > 0 {
log.Printf(
"zombie gc purged=%d",
deleted,
)
}
}
}()
}