mirror of
https://github.com/hanzoai/cd.git
synced 2026-10-30 14:56:45 +00:00
argoRedisHooks/NewArgoRedisHook, argoRepo/argoDB, argov1 and the argoio/argoutils import aliases were the only things left saying Argo in these packages; nothing here is matched by anything outside the process. Also renames a leftover "staging-argocd-demo" branch name in the webhook test fixtures.
42 lines
1006 B
Go
42 lines
1006 B
Go
package cache
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
"github.com/hanzokv/go/v9"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type redisReconnectHook struct {
|
|
reconnectCallback func()
|
|
}
|
|
|
|
func NewRedisReconnectHook(reconnectCallback func()) *redisReconnectHook {
|
|
return &redisReconnectHook{reconnectCallback: reconnectCallback}
|
|
}
|
|
|
|
func (hook *redisReconnectHook) DialHook(next kv.DialHook) kv.DialHook {
|
|
return func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
conn, err := next(ctx, network, addr)
|
|
return conn, err
|
|
}
|
|
}
|
|
|
|
func (hook *redisReconnectHook) ProcessHook(next kv.ProcessHook) kv.ProcessHook {
|
|
return func(ctx context.Context, cmd kv.Cmder) error {
|
|
var dnsError *net.DNSError
|
|
err := next(ctx, cmd)
|
|
if err != nil && errors.As(err, &dnsError) {
|
|
log.Warnf("Reconnect to redis because error: \"%v\"", err)
|
|
hook.reconnectCallback()
|
|
}
|
|
return err
|
|
}
|
|
}
|
|
|
|
func (hook *redisReconnectHook) ProcessPipelineHook(_ kv.ProcessPipelineHook) kv.ProcessPipelineHook {
|
|
return nil
|
|
}
|