Skip to content

Commit 4fb3b98

Browse files
authored
chore: document the limitations with the locker design (#848)
1 parent c9b34bd commit 4fb3b98

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ other instances checking to see if a new leader needs to be elected.
121121
- [**Locker**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithDistributedLocker):
122122
A locker can be used to lock each run of a job to a single instance of gocron.
123123
Locker can be at job or scheduler, if it is defined both at job and scheduler then locker of job will take precedence.
124+
- See Notes in the doc for [Locker](https://pkg.go.dev/github.com/go-co-op/gocron/v2#Locker) for
125+
details and limitations of the locker design.
124126
- Implementations: [go-co-op lockers](https://github.com/go-co-op?q=-lock&type=all&language=&sort=)
125127
(don't see what you need? request on slack to get a repo created to contribute it!)
126128

distributed.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ type Elector interface {
1818
// locker implementation handles time splay between schedulers.
1919
// The lock key passed is the job's name - which, if not set, defaults to the
2020
// go function's name, e.g. "pkg.myJob" for func myJob() {} in pkg
21+
//
22+
// Notes: The locker and scheduler do not handle synchronization of run times across
23+
// schedulers.
24+
//
25+
// 1. If you are using duration based jobs (DurationJob), you can utilize the JobOption
26+
// WithStartAt to set a start time for the job to the nearest time rounded to your
27+
// duration. For example, if you have a job that runs every 5 minutes, you can set
28+
// the start time to the nearest 5 minute e.g. 12:05, 12:10.
29+
//
30+
// 2. For all jobs, the implementation is still vulnerable to clockskew between scheduler
31+
// instances. This may result in a single scheduler instance running the majority of the
32+
// jobs.
33+
//
34+
// For distributed jobs, consider utilizing the Elector option if these notes are not acceptable
35+
// to your use case.
2136
type Locker interface {
2237
// Lock if an error is returned by lock, the job will not be scheduled.
2338
Lock(ctx context.Context, key string) (Lock, error)

0 commit comments

Comments
 (0)