mirror of
https://github.com/hackdiaz-dev/free-turn-proxy.git
synced 2026-10-12 09:41:53 +02:00
fix(clients): останавливать горячую перезагрузку базы по контексту
This commit is contained in:
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user