forked from go-co-op/gocron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locker.go
30 lines (25 loc) · 956 Bytes
/
locker.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
package gocron
import (
"context"
"errors"
)
var (
ErrFailedToConnectToRedis = errors.New("gocron: failed to connect to redis")
ErrFailedToObtainLock = errors.New("gocron: failed to obtain lock")
ErrFailedToReleaseLock = errors.New("gocron: failed to release lock")
)
// Locker represents the required interface to lock jobs when running multiple schedulers.
type Locker interface {
// Lock if an error is returned by lock, the job will not be scheduled.
Lock(ctx context.Context, key string) (Lock, error)
}
// Lock represents an obtained lock
type Lock interface {
Unlock(ctx context.Context) error
}
// Elector determines the leader from instances asking to be the leader. Only
// the leader runs jobs. If the leader goes down, a new leader will be elected.
type Elector interface {
// IsLeader should return an error if the job should not be scheduled and nil if the job should be scheduled.
IsLeader(ctx context.Context) error
}