diff --git a/cmd/cgat/main.go b/cmd/cgat/main.go index c063337b5c8e343d91b7b16164fa9dcf2166e25e..d22bb2882d183c8236d2ec57093f5e7d1b120128 100644 --- a/cmd/cgat/main.go +++ b/cmd/cgat/main.go @@ -26,7 +26,7 @@ func main() { // create pool rawPool := transaction.NewPool() - pool := gat.NewPool(rawPool) + pool := gat.NewPool(rawPool, 15*time.Second) postgres.AddPool("uniswap", pool) pool.AddRecipe("localhost", gat.TCPRecipe{ Database: "uniswap", diff --git a/lib/gat/pool.go b/lib/gat/pool.go index 2b7d76c049ca4df39a2a174d48b7783d5c5adc7e..1c1c01c929fce3da7eb9b466f9a566d6ac251e0d 100644 --- a/lib/gat/pool.go +++ b/lib/gat/pool.go @@ -58,7 +58,7 @@ type Pool struct { raw RawPool } -func NewPool(raw RawPool) *Pool { +func NewPool(raw RawPool, idleTimeout time.Duration) *Pool { onWait := make(chan struct{}) pool := &Pool{ ctx: Context{ @@ -79,7 +79,7 @@ func NewPool(raw RawPool) *Pool { now := time.Now() idle := pool.IdleSince() - for now.Sub(idle) > 15*time.Second { + for now.Sub(idle) > idleTimeout { if idle == (time.Time{}) { break } @@ -88,9 +88,9 @@ func NewPool(raw RawPool) *Pool { } if idle == (time.Time{}) { - wait = 15 * time.Second + wait = idleTimeout } else { - wait = now.Sub(idle.Add(15 * time.Second)) + wait = now.Sub(idle.Add(idleTimeout)) } time.Sleep(wait) diff --git a/lib/gat/pools/transaction/pool.go b/lib/gat/pools/transaction/pool.go index 05ef912541f8f9a0e006310e8b811ea02742fb5a..c79aa76bd35681359740beda64be8feb31cf2a4b 100644 --- a/lib/gat/pools/transaction/pool.go +++ b/lib/gat/pools/transaction/pool.go @@ -91,8 +91,8 @@ func (T *Pool) ScaleDown(amount int) (remaining int) { remaining = amount for i := 0; i < amount; i++ { - id, _ := T.s.GetIdleWorker() - if id == uuid.Nil { + id, idle := T.s.GetIdleWorker() + if id == uuid.Nil || idle == (time.Time{}) { break } worker := T.s.RemoveWorker(id)