Bump github.com/go-co-op/gocron from 1.17.0 to 1.18.0 (#155)

Bumps [github.com/go-co-op/gocron](https://github.com/go-co-op/gocron) from 1.17.0 to 1.18.0.
- [Release notes](https://github.com/go-co-op/gocron/releases)
- [Commits](https://github.com/go-co-op/gocron/compare/v1.17.0...v1.18.0)

---
updated-dependencies:
- dependency-name: github.com/go-co-op/gocron
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
dependabot[bot] 2022-11-08 16:33:49 -08:00 committed by GitHub
parent ccc366fb44
commit 5d3ebd7da6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 32 deletions

2
go.mod
View File

@ -7,7 +7,7 @@ require (
github.com/contribsys/faktory v1.6.2
github.com/contribsys/faktory_worker_go v1.6.0
github.com/feditools/go-lib v0.18.2
github.com/go-co-op/gocron v1.17.0
github.com/go-co-op/gocron v1.18.0
github.com/go-fed/activity v1.0.0
github.com/go-fed/httpsig v1.1.0
github.com/go-playground/validator/v10 v10.11.1

4
go.sum
View File

@ -114,8 +114,8 @@ github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmV
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-co-op/gocron v1.17.0 h1:IixLXsti+Qo0wMvmn6Kmjp2csk2ykpkcL+EmHmST18w=
github.com/go-co-op/gocron v1.17.0/go.mod h1:IpDBSaJOVfFw7hXZuTag3SCSkqazXBBUkbQ1m1aesBs=
github.com/go-co-op/gocron v1.18.0 h1:SxTyJ5xnSN4byCq7b10LmmszFdxQlSQJod8s3gbnXxA=
github.com/go-co-op/gocron v1.18.0/go.mod h1:sD/a0Aadtw5CpflUJ/lpP9Vfdk979Wl1Sg33HPHg0FY=
github.com/go-fed/activity v1.0.0 h1:j7w3auHZnVCjUcgA1mE+UqSOjFBhvW2Z2res3vNol+o=
github.com/go-fed/activity v1.0.0/go.mod h1:v4QoPaAzjWZ8zN2VFVGL5ep9C02mst0hQYHUpQwso4Q=
github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE=

View File

@ -12,4 +12,4 @@ The current plan is to maintain version 1 as long as possible incorporating any
Vulnerabilities can be reported by [opening an issue](https://github.com/go-co-op/gocron/issues/new/choose) or reaching out on Slack: [<img src="https://img.shields.io/badge/gophers-gocron-brightgreen?logo=slack">](https://gophers.slack.com/archives/CQ7T0T1FW)
We will do our best to addrerss any vulnerabilites in an expeditious manner.
We will do our best to addrerss any vulnerabilities in an expeditious manner.

View File

@ -27,6 +27,7 @@ const (
type executor struct {
jobFunctions chan jobFunction
stopCh chan struct{}
stoppedCh chan struct{}
limitMode limitMode
maxRunningJobs *semaphore.Weighted
}
@ -34,7 +35,8 @@ type executor struct {
func newExecutor() executor {
return executor{
jobFunctions: make(chan jobFunction, 1),
stopCh: make(chan struct{}, 1),
stopCh: make(chan struct{}),
stoppedCh: make(chan struct{}),
}
}
@ -47,6 +49,8 @@ func (e *executor) start() {
case f := <-e.jobFunctions:
runningJobsWg.Add(1)
go func() {
defer runningJobsWg.Done()
panicHandlerMutex.RLock()
defer panicHandlerMutex.RUnlock()
@ -58,8 +62,6 @@ func (e *executor) start() {
}()
}
defer runningJobsWg.Done()
if e.maxRunningJobs != nil {
if !e.maxRunningJobs.TryAcquire(1) {
@ -67,18 +69,17 @@ func (e *executor) start() {
case RescheduleMode:
return
case WaitMode:
for {
select {
case <-stopCtx.Done():
return
case <-f.ctx.Done():
return
default:
}
select {
case <-stopCtx.Done():
return
case <-f.ctx.Done():
return
default:
}
if err := e.maxRunningJobs.Acquire(f.ctx, 1); err != nil {
break
if e.maxRunningJobs.TryAcquire(1) {
break
}
}
}
}
@ -114,13 +115,13 @@ func (e *executor) start() {
case <-e.stopCh:
cancel()
runningJobsWg.Wait()
e.stopCh <- struct{}{}
close(e.stoppedCh)
return
}
}
}
func (e *executor) stop() {
e.stopCh <- struct{}{}
<-e.stopCh
close(e.stopCh)
<-e.stoppedCh
}

View File

@ -170,6 +170,8 @@ func (s *Scheduler) scheduleNextRun(job *Job) (bool, nextRun) {
return false, nextRun{}
}
lastRun := now
if job.neverRan() {
// Increment startAtTime to the future
if !job.startAtTime.IsZero() && job.startAtTime.Before(now) {
@ -185,6 +187,8 @@ func (s *Scheduler) scheduleNextRun(job *Job) (bool, nextRun) {
job.startAtTime = job.startAtTime.Add(duration * count)
}
}
} else {
lastRun = job.LastRun()
}
if !job.shouldRun() {
@ -192,10 +196,12 @@ func (s *Scheduler) scheduleNextRun(job *Job) (bool, nextRun) {
return false, nextRun{}
}
next := s.durationToNextRun(now, job)
next := s.durationToNextRun(lastRun, job)
job.setLastRun(job.NextRun())
if next.dateTime.IsZero() {
job.setNextRun(now.Add(next.duration))
next.dateTime = lastRun.Add(next.duration)
job.setNextRun(next.dateTime)
} else {
job.setNextRun(next.dateTime)
}
@ -350,12 +356,6 @@ func (s *Scheduler) calculateDays(job *Job, lastRun time.Time) nextRun {
if job.getInterval() == 1 {
lastRunDayPlusJobAtTime := s.roundToMidnight(lastRun).Add(job.getAtTime(lastRun))
// handle occasional occurrence of job running to quickly / too early such that last run was within a second of now
lastRunUnix, nowUnix := job.LastRun().Unix(), s.now().Unix()
if lastRunUnix == nowUnix || lastRunUnix == nowUnix-1 || lastRunUnix == nowUnix+1 {
lastRun = lastRunDayPlusJobAtTime
}
if shouldRunToday(lastRun, lastRunDayPlusJobAtTime) {
return nextRun{duration: until(lastRun, lastRunDayPlusJobAtTime), dateTime: lastRunDayPlusJobAtTime}
}
@ -539,6 +539,13 @@ func (s *Scheduler) run(job *Job) {
}
job.mu.Lock()
if job.function == nil {
job.mu.Unlock()
s.Remove(job)
return
}
defer job.mu.Unlock()
if job.runWithDetails {
@ -555,7 +562,6 @@ func (s *Scheduler) run(job *Job) {
}
s.executor.jobFunctions <- job.jobFunction.copy()
job.setLastRun(s.now())
job.runCount++
}
@ -571,7 +577,17 @@ func (s *Scheduler) runContinuous(job *Job) {
s.run(job)
}
job.setTimer(s.timer(next.duration, func() {
nextRun := next.dateTime.Sub(s.now())
if nextRun < 0 {
time.Sleep(absDuration(nextRun))
shouldRun, next := s.scheduleNextRun(job)
if !shouldRun {
return
}
nextRun = next.dateTime.Sub(s.now())
}
job.setTimer(s.timer(nextRun, func() {
if !next.dateTime.IsZero() {
for {
n := s.now().UnixNano() - next.dateTime.UnixNano()

2
vendor/modules.txt vendored
View File

@ -40,7 +40,7 @@ github.com/felixge/httpsnoop
# github.com/fsnotify/fsnotify v1.6.0
## explicit; go 1.16
github.com/fsnotify/fsnotify
# github.com/go-co-op/gocron v1.17.0
# github.com/go-co-op/gocron v1.18.0
## explicit; go 1.19
github.com/go-co-op/gocron
# github.com/go-fed/activity v1.0.0