Commit fd14b971 authored by Vladimir Barsukov's avatar Vladimir Barsukov
Browse files

add sleep on try

parent d5132e81
package zdb
import (
"fmt"
"github.com/jackc/pgx/v5/pgxpool"
)
......@@ -31,3 +32,7 @@ func (c connMode) String() string {
return "unknown"
}
}
func (c conn) ToString() string {
return fmt.Sprintf("%s: %s:%d", c.Mode, c.Config().ConnConfig.Host, c.Config().ConnConfig.Port)
}
......@@ -35,6 +35,7 @@ type Pool struct {
Continues []string
ContinuesTry []string
TryOnError int
TryOnSleep time.Duration
}
func New() *Pool {
......@@ -46,6 +47,7 @@ func New() *Pool {
Continues: []string{"connect", "EOF", "conflict with recovery"},
ContinuesTry: []string{"conflict with recovery"},
TryOnError: 1,
TryOnSleep: time.Second * 5,
}
}
......@@ -152,13 +154,15 @@ func (d *Pool) execWrapper(pool connMode, dst any, f func(conn *conn, dst1 any)
if try < d.TryOnError && contains(err.Error(), d.ContinuesTry) {
try++
d.logger.Printf("DB_EXEC_WRAPPER_REPEAT_ERR: TRY: %d, %s", try, err.Error())
d.logger.Printf("DB_EXEC_WRAPPER_REPEAT_ERR: SRV: %s TRY: %d; %s", q.ToString(), try, err.Error())
time.Sleep(d.TryOnSleep)
goto repeat
}
if contains(err.Error(), d.Continues) {
d.setNotAliveConn(q)
d.logger.Printf("DB_EXEC_WRAPPER_ERR: %s", err.Error())
d.logger.Printf("DB_EXEC_WRAPPER_ERR: SRV: %s; %s", q.ToString(), err.Error())
continue
} else {
return err
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment