feat: media duplicate purge, part 2 of 3: the automatic purge scheduler (Go only)

This commit is contained in:
fsylvain committed 2026-10-05 19:44:15 +02:00
1 parent e82d0ce254
commit 1a55a39425
18 files changed
+1389 -39

No files matched your search

+12 -3
View File
@@ -81,7 +81,7 @@ func run() error {
validator.InitValidator()
server := newServer(api.InitRoutes(container, settings), settings)
return serveUntilStopped(server, settings, container.RecordRunningInfoUseCase.Record)
return serveUntilStopped(server, settings, container.RecordRunningInfoUseCase.Record, container.PurgeScheduler.Run)
}
func initEnvVariables() {
@@ -132,9 +132,18 @@ func newServer(handler http.Handler, settings config.Settings) *http.Server {
}
}
func serveUntilStopped(server *http.Server, settings config.Settings, recordRunning func() error) error {
func serveUntilStopped(server *http.Server, settings config.Settings, recordRunning func() error, runScheduler func(context.Context)) error {
stopSignal, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
schedulerDone := make(chan struct{})
go func() {
defer close(schedulerDone)
runScheduler(stopSignal)
}()
defer func() {
stop()
<-schedulerDone
}()
serverErr := make(chan error, 1)
go listen(server, serverErr, settings, recordRunning)