mirror of
https://github.com/lukaszraczylo/go-simple-graphql.git
synced 2026-10-18 01:27:25 +00:00
fixup! Add pool management.
This commit is contained in:
@@ -236,16 +236,15 @@ func (b *BaseClient) refreshConnectionPool() {
|
|||||||
|
|
||||||
// StopPoolMonitor gracefully stops the pool health monitor
|
// StopPoolMonitor gracefully stops the pool health monitor
|
||||||
// Call this when shutting down the application
|
// Call this when shutting down the application
|
||||||
|
// Uses sync.Once to ensure it only executes once, preventing race conditions
|
||||||
func (b *BaseClient) StopPoolMonitor() {
|
func (b *BaseClient) StopPoolMonitor() {
|
||||||
if b.pool_warmup_enabled {
|
if b.pool_warmup_enabled {
|
||||||
b.Logger.Info(&libpack_logger.LogMessage{
|
b.pool_stop_once.Do(func() {
|
||||||
Message: "Stopping pool monitor",
|
b.Logger.Info(&libpack_logger.LogMessage{
|
||||||
Pairs: nil,
|
Message: "Stopping pool monitor",
|
||||||
|
Pairs: nil,
|
||||||
|
})
|
||||||
|
b.pool_stop <- true
|
||||||
})
|
})
|
||||||
select {
|
|
||||||
case b.pool_stop <- true:
|
|
||||||
default:
|
|
||||||
// Channel already has a value or monitor already stopped
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package gql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
cache "github.com/lukaszraczylo/go-simple-graphql/cache"
|
cache "github.com/lukaszraczylo/go-simple-graphql/cache"
|
||||||
@@ -22,6 +23,7 @@ type BaseClient struct {
|
|||||||
pool_warmup_query string // Query to use for warming up connections
|
pool_warmup_query string // Query to use for warming up connections
|
||||||
pool_health_interval time.Duration // Interval for pool health checks
|
pool_health_interval time.Duration // Interval for pool health checks
|
||||||
pool_stop chan bool // Channel to stop pool monitor
|
pool_stop chan bool // Channel to stop pool monitor
|
||||||
|
pool_stop_once sync.Once // Ensures StopPoolMonitor is called only once
|
||||||
MaxGoRoutines int
|
MaxGoRoutines int
|
||||||
cache_global bool
|
cache_global bool
|
||||||
retries_enable bool
|
retries_enable bool
|
||||||
|
|||||||
Reference in New Issue
Block a user