feat: add revision number to proxy and layers to identify changes
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
@ -14,7 +14,9 @@ const (
|
||||
)
|
||||
|
||||
type ProxyRepository struct {
|
||||
client redis.UniversalClient
|
||||
client redis.UniversalClient
|
||||
txMaxAttempts int
|
||||
txRetryBaseDelay time.Duration
|
||||
}
|
||||
|
||||
// GetProxy implements store.ProxyRepository
|
||||
@ -22,7 +24,7 @@ func (r *ProxyRepository) GetProxy(ctx context.Context, name store.ProxyName) (*
|
||||
key := proxyKey(name)
|
||||
var proxyItem *proxyItem
|
||||
|
||||
err := WithTx(ctx, r.client, key, func(ctx context.Context, tx *redis.Tx) error {
|
||||
err := WithRetry(ctx, r.client, key, func(ctx context.Context, tx *redis.Tx) error {
|
||||
pItem, err := r.txGetProxyItem(ctx, tx, name)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -31,7 +33,7 @@ func (r *ProxyRepository) GetProxy(ctx context.Context, name store.ProxyName) (*
|
||||
proxyItem = pItem
|
||||
|
||||
return nil
|
||||
})
|
||||
}, r.txMaxAttempts, r.txRetryBaseDelay)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -89,6 +91,7 @@ func (r *ProxyRepository) CreateProxy(ctx context.Context, name store.ProxyName,
|
||||
CreatedAt: wrap(now),
|
||||
UpdatedAt: wrap(now),
|
||||
Weight: 0,
|
||||
Revision: 0,
|
||||
Enabled: false,
|
||||
},
|
||||
To: to,
|
||||
@ -191,7 +194,7 @@ func (r *ProxyRepository) UpdateProxy(ctx context.Context, name store.ProxyName,
|
||||
key := proxyKey(name)
|
||||
var proxyItem proxyItem
|
||||
|
||||
err := WithTx(ctx, r.client, key, func(ctx context.Context, tx *redis.Tx) error {
|
||||
err := WithRetry(ctx, r.client, key, func(ctx context.Context, tx *redis.Tx) error {
|
||||
item, err := r.txGetProxyItem(ctx, tx, name)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -214,6 +217,7 @@ func (r *ProxyRepository) UpdateProxy(ctx context.Context, name store.ProxyName,
|
||||
}
|
||||
|
||||
item.UpdatedAt = wrap(time.Now().UTC())
|
||||
item.Revision = item.Revision + 1
|
||||
|
||||
_, err = tx.TxPipelined(ctx, func(p redis.Pipeliner) error {
|
||||
p.HMSet(ctx, key, item.proxyHeaderItem)
|
||||
@ -228,7 +232,7 @@ func (r *ProxyRepository) UpdateProxy(ctx context.Context, name store.ProxyName,
|
||||
proxyItem = *item
|
||||
|
||||
return nil
|
||||
})
|
||||
}, r.txMaxAttempts, r.txRetryBaseDelay)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -241,9 +245,11 @@ func (r *ProxyRepository) UpdateProxy(ctx context.Context, name store.ProxyName,
|
||||
return proxy, nil
|
||||
}
|
||||
|
||||
func NewProxyRepository(client redis.UniversalClient) *ProxyRepository {
|
||||
func NewProxyRepository(client redis.UniversalClient, txMaxAttempts int, txRetryBaseDelay time.Duration) *ProxyRepository {
|
||||
return &ProxyRepository{
|
||||
client: client,
|
||||
client: client,
|
||||
txMaxAttempts: 20,
|
||||
txRetryBaseDelay: txRetryBaseDelay,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user