satellite/satellitedb: remove direct import of pgxerrcode
Use the provided ConstraintViolation method of the pgutil package rather than importing jackc pgxerrcode directly. Change-Id: I4e86713000b3f5f0aadd54beee8ee239f0c8df8e
This commit is contained in:
parent
998835a0c3
commit
cd89e1e557
@ -10,7 +10,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
pgxerrcode "github.com/jackc/pgerrcode"
|
|
||||||
"github.com/jackc/pgx/v4"
|
"github.com/jackc/pgx/v4"
|
||||||
"github.com/zeebo/errs"
|
"github.com/zeebo/errs"
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ func (db billingDB) Insert(ctx context.Context, billingTX billing.Transaction) (
|
|||||||
dbx.BillingTransaction_Timestamp(billingTX.Timestamp))
|
dbx.BillingTransaction_Timestamp(billingTX.Timestamp))
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
if isDuplicateEntryError(err) {
|
if pgerrcode.IsConstraintViolation(err) {
|
||||||
retryCount++
|
retryCount++
|
||||||
if retryCount > 5 {
|
if retryCount > 5 {
|
||||||
return 0, Error.New("Unable to insert new billing transaction after several retries: %v", err)
|
return 0, Error.New("Unable to insert new billing transaction after several retries: %v", err)
|
||||||
@ -244,7 +243,3 @@ func handleMetaDataZeroValue(metaData []byte) []byte {
|
|||||||
}
|
}
|
||||||
return []byte(`{}`)
|
return []byte(`{}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func isDuplicateEntryError(err error) bool {
|
|
||||||
return pgerrcode.FromError(err) == pgxerrcode.UniqueViolation
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user