fix(clients): останавливать горячую перезагрузку базы по контексту

This commit is contained in:
samosvalishe committed 2026-09-21 13:43:01 +03:00
1 parent fd5c4f92a5
commit b621182ce4
2 files changed
+9 -3

No files matched your search

+1 -1
View File
@@ -110,7 +110,7 @@ func main() {
logger.Errorf("Failed to open clients-file: %v", err) logger.Errorf("Failed to open clients-file: %v", err)
os.Exit(1) os.Exit(1)
} }
d.StartHotReload(10 * time.Second) d.StartHotReload(ctx, 10*time.Second)
db = d db = d
logger.Infof("Client ID authorization enabled via %s", cfg.ClientsFile) logger.Infof("Client ID authorization enabled via %s", cfg.ClientsFile)
} }
+8 -2
View File
@@ -1,6 +1,7 @@
package clientsdb package clientsdb
import ( import (
"context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
@@ -41,13 +42,18 @@ func New(path string) (*DB, error) {
return db, nil return db, nil
} }
func (db *DB) StartHotReload(interval time.Duration) { func (db *DB) StartHotReload(ctx context.Context, interval time.Duration) {
go func() { go func() {
ticker := time.NewTicker(interval) ticker := time.NewTicker(interval)
defer ticker.Stop() defer ticker.Stop()
for range ticker.C { for {
select {
case <-ctx.Done():
return
case <-ticker.C:
db.loadIfModified() db.loadIfModified()
} }
}
}() }()
} }