Skip to content

Commit 4277a15

Browse files
committed
Update docs, tests, and release prep
1 parent 5814fbc commit 4277a15

16 files changed

+230
-199
lines changed

Diff for: README.md

+22-18
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ gocron is a job scheduling package which lets you run Go functions at pre-determ
88
If you want to chat, you can find us on Slack at
99
[<img src="https://img.shields.io/badge/gophers-gocron-brightgreen?logo=slack">](https://gophers.slack.com/archives/CQ7T0T1FW)
1010

11-
## Concepts
12-
13-
- **Job**: The encapsulates a "task", which is made up of a go func and any function parameters, and then
14-
provides the scheduler with the time the job should be scheduled to run.
15-
- **Executor**: The executor, calls the "task" function and manages the complexities of different job
16-
execution timing (e.g. singletons that shouldn't overrun each other, limiting the max number of jobs running)
17-
- **Scheduler**: The scheduler keeps track of all the jobs and sends each job to the executor when
18-
it is ready to be run.
19-
2011
## Quick Start
2112

2213
```
@@ -70,6 +61,16 @@ func main() {
7061
}
7162
```
7263

64+
## Concepts
65+
66+
- **Job**: The job encapsulates a "task", which is made up of a go function and any function parameters. The Job then
67+
provides the scheduler with the time the job should next be scheduled to run.
68+
- **Scheduler**: The scheduler keeps track of all the jobs and sends each job to the executor when
69+
it is ready to be run.
70+
- **Executor**: The executor calls the job's task and manages the complexities of different job
71+
execution timing requirements (e.g. singletons that shouldn't overrun each other, limiting the max number of jobs running)
72+
73+
7374
## Features
7475

7576
- **Job types**: Jobs can be run at various intervals.
@@ -85,14 +86,15 @@ func main() {
8586
Jobs can be run every x weeks on specific days of the week and at specific times.
8687
- [**Monthly**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#MonthlyJob):
8788
Jobs can be run every x months on specific days of the month and at specific times.
88-
- **Limited Concurrency**: Jobs can be limited individually or across the entire scheduler.
89+
- **Concurrency Limits**: Jobs can be limited individually or across the entire scheduler.
8990
- [**Per job limiting with singleton mode**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithSingletonMode):
9091
Jobs can be limited to a single concurrent execution that either reschedules (skips overlapping executions)
9192
or queues (waits for the previous execution to finish).
9293
- [**Per scheduler limiting with limit mode**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithLimitConcurrentJobs):
9394
Jobs can be limited to a certain number of concurrent executions across the entire scheduler
9495
using either reschedule (skip when the limit is met) or queue (jobs are added to a queue to
9596
wait for the limit to be available).
97+
- **Note:** A scheduler limit and a job limit can both be enabled.
9698
- **Distributed instances of gocron**: Multiple instances of gocron can be run.
9799
- [**Elector**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithDistributedElector):
98100
An elector can be used to elect a single instance of gocron to run as the primary with the
@@ -103,31 +105,33 @@ func main() {
103105
- Implementations: [go-co-op lockers](https://github.com/go-co-op?q=-lock&type=all&language=&sort=)
104106
- **Events**: Job events can trigger actions.
105107
- [**Listeners**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithEventListeners):
106-
[Event listeners](https://pkg.go.dev/github.com/go-co-op/gocron/v2#EventListener)
107-
can be added to a job or all jobs in the
108+
Can be added to a job, with [event listeners](https://pkg.go.dev/github.com/go-co-op/gocron/v2#EventListener),
109+
or all jobs across the
108110
[scheduler](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithGlobalJobOptions)
109111
to listen for job events and trigger actions.
110-
- **Options**: Many job and scheduler options are available
112+
- **Options**: Many job and scheduler options are available.
111113
- [**Job options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#JobOption):
112114
Job options can be set when creating a job using `NewJob`.
113115
- [**Global job options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithGlobalJobOptions):
114-
Global job options can be set when creating a scheduler using `NewScheduler`.
116+
Global job options can be set when creating a scheduler using `NewScheduler`
117+
and the `WithGlobalJobOptions` option.
115118
- [**Scheduler options**](https://pkg.go.dev/github.com/go-co-op/gocron/v2#SchedulerOption):
116119
Scheduler options can be set when creating a scheduler using `NewScheduler`.
117120
- **Logging**: Logs can be enabled.
118121
- [Logger](https://pkg.go.dev/github.com/go-co-op/gocron/v2#Logger):
119122
The Logger interface can be implemented with your desired logging library.
120123
The provided NewLogger uses the standard library's log package.
121-
- **Mocking**: The gocron library is set up to enable testing.
124+
- **Testing**: The gocron library is set up to enable testing.
122125
- Mocks are provided in [the mock package](mocks) using [gomock](https://github.com/uber-go/mock).
123126
- Time can be mocked by passing in a [FakeClock](https://pkg.go.dev/github.com/jonboulle/clockwork#FakeClock)
124127
to [WithClock](https://pkg.go.dev/github.com/go-co-op/gocron/v2#WithClock) -
125-
see the example on WithClock in the go-docs.
128+
see the [example on WithClock](https://pkg.go.dev/github.com/go-co-op/gocron/v2#example-WithClock).
126129

127130
## Supporters
128131

129-
[Jetbrains](https://www.jetbrains.com/?from=gocron) supports this project with Intellij licenses.
130-
We appreciate their support for free and open source software!
132+
We appreciate the support for free and open source software!
133+
134+
- [Jetbrains](https://www.jetbrains.com/?from=gocron) supports this project with Intellij licenses.
131135

132136
## Star History
133137

Diff for: distributed.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate mockgen -source=distributed.go -destination=mocks/distributed.go -package=gocronmocks
1+
//go:generate mockgen -destination=mocks/distributed.go -package=gocronmocks . Elector,Locker,Lock
22
package gocron
33

44
import (

Diff for: executor.go

+7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,13 @@ func (e *executor) limitModeRunner(name string, in chan uuid.UUID, wg *waitGroup
231231
return
232232
case e.jobIDsOut <- j.id:
233233
}
234+
// remove the limiter block to allow another job to be scheduled
235+
if limitMode == LimitModeReschedule {
236+
select {
237+
case <-rescheduleLimiter:
238+
default:
239+
}
240+
}
234241
continue
235242
}
236243
e.limitMode.singletonJobs[id] = struct{}{}

Diff for: go.mod

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ require (
88
github.com/robfig/cron/v3 v3.0.1
99
github.com/stretchr/testify v1.8.4
1010
go.uber.org/goleak v1.3.0
11-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
11+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
1212
)
1313

1414
require (
1515
github.com/davecgh/go-spew v1.1.1 // indirect
1616
github.com/kr/text v0.2.0 // indirect
17-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
1817
github.com/pmezard/go-difflib v1.0.0 // indirect
19-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
18+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2019
gopkg.in/yaml.v3 v3.0.1 // indirect
2120
)

Diff for: go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
55
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
66
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
77
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
8+
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
9+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
810
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
911
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
1012
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1113
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
12-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
13-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
1414
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1515
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1616
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
@@ -19,10 +19,10 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
1919
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
2020
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
2121
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
22-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
23-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
22+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
23+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
2424
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
25-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
26-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
25+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
26+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
2727
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2828
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Diff for: job.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate mockgen -source=job.go -destination=mocks/job.go -package=gocronmocks
1+
//go:generate mockgen -destination=mocks/job.go -package=gocronmocks . Job
22
package gocron
33

44
import (

Diff for: job_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,9 @@ func TestJob_LastRun(t *testing.T) {
313313
testTime := time.Date(2000, 1, 1, 0, 0, 0, 0, time.Local)
314314
fakeClock := clockwork.NewFakeClockAt(testTime)
315315

316-
s, err := newTestScheduler(
316+
s := newTestScheduler(t,
317317
WithClock(fakeClock),
318318
)
319-
require.NoError(t, err)
320319

321320
j, err := s.NewJob(
322321
DurationJob(

Diff for: logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate mockgen -source=logger.go -destination=mocks/logger.go -package=gocronmocks
1+
//go:generate mockgen -destination=mocks/logger.go -package=gocronmocks . Logger
22
package gocron
33

44
import (

Diff for: mocks/distributed.go

+78-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: mocks/go.mod

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/go-co-op/gocronmocks/v2
33
go 1.20
44

55
require (
6-
github.com/go-co-op/gocron/v2 v2.0.0-rc1
6+
github.com/go-co-op/gocron/v2 v2.0.0-rc4
77
github.com/google/uuid v1.4.0
88
go.uber.org/mock v0.3.0
99
)
1010

1111
require (
1212
github.com/jonboulle/clockwork v0.4.0 // indirect
1313
github.com/robfig/cron/v3 v3.0.1 // indirect
14-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
14+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb // indirect
1515
)

Diff for: mocks/go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/go-co-op/gocron/v2 v2.0.0-rc1 h1:qkj0WVO6uh6ibZa2CQ0Ifxk3A+c6rawZnIby94/5sAM=
3-
github.com/go-co-op/gocron/v2 v2.0.0-rc1/go.mod h1:3SLoqKnyORFVN0VvFFb1383hM4WD9XHBPn9aUUp7sQs=
2+
github.com/go-co-op/gocron/v2 v2.0.0-rc4 h1:KFYg2CzyHZwPZL/uNnQKEyeL9oKEUQbiLThArcZaVmw=
3+
github.com/go-co-op/gocron/v2 v2.0.0-rc4/go.mod h1:3SLoqKnyORFVN0VvFFb1383hM4WD9XHBPn9aUUp7sQs=
44
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
55
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
66
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
@@ -12,6 +12,6 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU
1212
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
1313
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
1414
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
15-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
16-
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
15+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
16+
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
1717
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

0 commit comments

Comments
 (0)