fix: preserve media store across config reloads

- Reuse existing MediaStore instance instead of recreating on every reload
- Don't stop MediaStore on reload to preserve file references and allow cleanup to continue
- Prevents loss of uploaded file references when using /reload command

Note: Changes to media_cleanup config require restart to take effect.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
Harshit 2026-03-29 22:05:22 +02:00
parent 93f4c4a843
commit 541ad90b3d

View file

@ -281,6 +281,9 @@ func setupAndStartServices(
}
fmt.Println("✓ Heartbeat service started")
// Initialize MediaStore for file uploads
// Note: Changes to media_cleanup config require restart to take effect
if runningServices.MediaStore == nil {
runningServices.MediaStore = media.NewFileMediaStoreWithCleanup(media.MediaCleanerConfig{
Enabled: cfg.Tools.MediaCleanup.Enabled,
MaxAge: time.Duration(cfg.Tools.MediaCleanup.MaxAge) * time.Minute,
@ -289,6 +292,7 @@ func setupAndStartServices(
if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok {
fms.Start()
}
}
runningServices.ChannelManager, err = channels.NewManager(cfg, msgBus, runningServices.MediaStore)
if err != nil {
@ -359,7 +363,9 @@ func stopAndCleanupServices(runningServices *services, shutdownTimeout time.Dura
if runningServices.CronService != nil {
runningServices.CronService.Stop()
}
if runningServices.MediaStore != nil {
// Don't stop MediaStore on reload to preserve file references
// and allow cleanup goroutine to continue running
if !isReload && runningServices.MediaStore != nil {
if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok {
fms.Stop()
}
@ -480,6 +486,9 @@ func restartServices(
}
fmt.Println(" ✓ Heartbeat service restarted")
// Reuse existing MediaStore to preserve file references across reloads
// Note: Changes to media_cleanup config require restart to take effect
if runningServices.MediaStore == nil {
runningServices.MediaStore = media.NewFileMediaStoreWithCleanup(media.MediaCleanerConfig{
Enabled: cfg.Tools.MediaCleanup.Enabled,
MaxAge: time.Duration(cfg.Tools.MediaCleanup.MaxAge) * time.Minute,
@ -488,6 +497,7 @@ func restartServices(
if fms, ok := runningServices.MediaStore.(*media.FileMediaStore); ok {
fms.Start()
}
}
al.SetMediaStore(runningServices.MediaStore)
al.SetChannelManager(runningServices.ChannelManager)