[v9.3.x] Chore: Extract server lock error so it can be used with errors.As (#58906)

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
(cherry picked from commit 7e9d94cfda)

Co-authored-by: Jo <joao.guerreiro@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-11-17 15:30:24 +01:00
committed by GitHub
co-authored by Jo
parent 710124b5de
commit 311b4b9b6f
2 changed files with 10 additions and 2 deletions
+9
View 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
}
+1 -2
View File
@@ -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()