Refactor api package
This commit is contained in:
@@ -7,6 +7,16 @@ import (
|
||||
"github.com/sosedoff/pgweb/pkg/command"
|
||||
)
|
||||
|
||||
// StartSessionCleanup starts a goroutine to cleanup idle database sessions
|
||||
func StartSessionCleanup() {
|
||||
for range time.Tick(time.Minute) {
|
||||
if command.Opts.Debug {
|
||||
log.Println("Triggering idle session deletion")
|
||||
}
|
||||
cleanupIdleSessions()
|
||||
}
|
||||
}
|
||||
|
||||
func cleanupIdleSessions() {
|
||||
ids := []string{}
|
||||
|
||||
@@ -16,11 +26,11 @@ func cleanupIdleSessions() {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
}
|
||||
|
||||
// Close and delete idle sessions
|
||||
if len(ids) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// Close and delete idle sessions
|
||||
log.Println("Closing", len(ids), "idle sessions")
|
||||
for _, id := range ids {
|
||||
// TODO: concurrent map edit will trigger panic
|
||||
@@ -29,17 +39,3 @@ func cleanupIdleSessions() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func StartSessionCleanup() {
|
||||
ticker := time.NewTicker(time.Minute)
|
||||
|
||||
for {
|
||||
<-ticker.C
|
||||
|
||||
if command.Opts.Debug {
|
||||
log.Println("Triggering idle session deletion")
|
||||
}
|
||||
|
||||
cleanupIdleSessions()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user