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

This commit is contained in:
samosvalishe
2026-09-21 13:43:01 +03:00
parent fd5c4f92a5
commit b621182ce4
2 changed files with 10 additions and 4 deletions
+1 -1
View File
@@ -110,7 +110,7 @@ func main() {
logger.Errorf("Failed to open clients-file: %v", err)
os.Exit(1)
}
d.StartHotReload(10 * time.Second)
d.StartHotReload(ctx, 10*time.Second)
db = d
logger.Infof("Client ID authorization enabled via %s", cfg.ClientsFile)
}
+9 -3
View File
@@ -1,6 +1,7 @@
package clientsdb
import (
"context"
"encoding/json"
"fmt"
"io"
@@ -41,12 +42,17 @@ func New(path string) (*DB, error) {
return db, nil
}
func (db *DB) StartHotReload(interval time.Duration) {
func (db *DB) StartHotReload(ctx context.Context, interval time.Duration) {
go func() {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
db.loadIfModified()
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
db.loadIfModified()
}
}
}()
}