mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Extract server lock error so it can be used with errors.As (#58899)
chore: extract server lock Error so it can be used with error.As
This commit is contained in:
parent
5ea077c440
commit
7e9d94cfda
9
pkg/infra/serverlock/errors.go
Normal file
9
pkg/infra/serverlock/errors.go
Normal file
@ -0,0 +1,9 @@
|
||||
package serverlock
|
||||
|
||||
type ServerLockExistsError struct {
|
||||
actionName string
|
||||
}
|
||||
|
||||
func (e *ServerLockExistsError) Error() string {
|
||||
return "there is already a lock for this actionName: " + e.actionName
|
||||
}
|
@ -2,7 +2,6 @@ package serverlock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
@ -185,7 +184,7 @@ func (sl *ServerLockService) acquireForRelease(ctx context.Context, actionName s
|
||||
if len(lockRows) > 0 {
|
||||
result := lockRows[0]
|
||||
if sl.isLockWithinInterval(result, maxInterval) {
|
||||
return errors.New("there is already a lock for this actionName: " + actionName)
|
||||
return &ServerLockExistsError{actionName: actionName}
|
||||
} else {
|
||||
// lock has timeouted, so we update the timestamp
|
||||
result.LastExecution = time.Now().Unix()
|
||||
|
Loading…
Reference in New Issue
Block a user