-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
66 lines (55 loc) · 1.72 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package dlocker
import (
"context"
"github.com/p8bin/dlocker/models"
)
// Manages locks
type Locker interface {
// Set a lock (and wait for previous) or return ErrNoLuck if no luck or an unexpected error occurs
LockWithWait(
ctx context.Context,
lock models.Lock,
) (lockCtx LockContext, cancel context.CancelFunc, err error)
// Extend existing lock
ExtendLock(
ctx context.Context,
lockCtx LockContext,
) (newLockCtx LockContext, cancel context.CancelFunc, err error)
// Release lock or return ErrNoLuck if no luck or an unexpected error occurs
Unlock(
ctx context.Context,
lockCtx LockContext,
) (err error)
}
// Extends existing lock
type LockExtender interface {
LockWithWait(ctx context.Context) (exCtx context.Context, err error)
Unlock(ctx context.Context, wait bool)
}
// Creates lock records in a persistent storage.
type StorageProvider interface {
// Returns LockRecord or error ErrNotFound if not found or unexpected error.
GetLockRecord(
ctx context.Context,
jobName string,
) (lr models.LockRecord, err error)
// Creates LockRecord or returns error ErrDuplicate if already exists or unexpected error.
CreateLockRecord(
ctx context.Context,
lr models.LockRecord,
) (err error)
// Updates LockRecord with new values or return error ErrNotFound if not found or unexpected error.
// Returns ErrNotSupported in case storage does not support updates (in this case storage must handle ttl)
UpdateLockRecord(
ctx context.Context,
jobName string,
version string,
patch models.LockRecordPatch,
) (err error)
}
// Lock context
type LockContext interface {
context.Context
GetLock() models.Lock
GetLockRecord() models.LockRecord
}