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 LayerRepository struct {
|
||||
client redis.UniversalClient
|
||||
client redis.UniversalClient
|
||||
txMaxAttempts int
|
||||
txRetryBaseDelay time.Duration
|
||||
}
|
||||
|
||||
// CreateLayer implements store.LayerRepository
|
||||
@ -24,11 +26,12 @@ func (r *LayerRepository) CreateLayer(ctx context.Context, proxyName store.Proxy
|
||||
|
||||
layerItem := &layerItem{
|
||||
layerHeaderItem: layerHeaderItem{
|
||||
Proxy: string(proxyName),
|
||||
Name: string(layerName),
|
||||
Type: string(layerType),
|
||||
Weight: 0,
|
||||
Enabled: false,
|
||||
Proxy: string(proxyName),
|
||||
Name: string(layerName),
|
||||
Type: string(layerType),
|
||||
Weight: 0,
|
||||
Revision: 0,
|
||||
Enabled: false,
|
||||
},
|
||||
|
||||
CreatedAt: wrap(now),
|
||||
@ -96,7 +99,7 @@ func (r *LayerRepository) GetLayer(ctx context.Context, proxyName store.ProxyNam
|
||||
key := layerKey(proxyName, layerName)
|
||||
var layerItem *layerItem
|
||||
|
||||
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.txGetLayerItem(ctx, tx, proxyName, layerName)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -105,7 +108,7 @@ func (r *LayerRepository) GetLayer(ctx context.Context, proxyName store.ProxyNam
|
||||
layerItem = pItem
|
||||
|
||||
return nil
|
||||
})
|
||||
}, r.txMaxAttempts, r.txRetryBaseDelay)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -197,7 +200,7 @@ func (r *LayerRepository) UpdateLayer(ctx context.Context, proxyName store.Proxy
|
||||
key := layerKey(proxyName, layerName)
|
||||
var layerItem layerItem
|
||||
|
||||
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.txGetLayerItem(ctx, tx, proxyName, layerName)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
@ -216,6 +219,7 @@ func (r *LayerRepository) UpdateLayer(ctx context.Context, proxyName store.Proxy
|
||||
}
|
||||
|
||||
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.layerHeaderItem)
|
||||
@ -230,7 +234,7 @@ func (r *LayerRepository) UpdateLayer(ctx context.Context, proxyName store.Proxy
|
||||
layerItem = *item
|
||||
|
||||
return nil
|
||||
})
|
||||
}, r.txMaxAttempts, r.txRetryBaseDelay)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
@ -243,9 +247,11 @@ func (r *LayerRepository) UpdateLayer(ctx context.Context, proxyName store.Proxy
|
||||
return layer, nil
|
||||
}
|
||||
|
||||
func NewLayerRepository(client redis.UniversalClient) *LayerRepository {
|
||||
func NewLayerRepository(client redis.UniversalClient, txMaxAttempts int, txRetryBaseDelay time.Duration) *LayerRepository {
|
||||
return &LayerRepository{
|
||||
client: client,
|
||||
client: client,
|
||||
txMaxAttempts: txMaxAttempts,
|
||||
txRetryBaseDelay: txRetryBaseDelay,
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user