mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-10-29 05:02:25 -05:00
[chore] update go-sched pkg (#3357)
* update go-sched to v1.2.4 which removes some now unused dependencies * whoops, remove test output
This commit is contained in:
parent
82b9515a9d
commit
f3e2d36d64
27 changed files with 33 additions and 4933 deletions
32
vendor/codeberg.org/gruf/go-sched/job.go
generated
vendored
32
vendor/codeberg.org/gruf/go-sched/job.go
generated
vendored
|
|
@ -4,9 +4,9 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-atomics"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// Job encapsulates logic for a scheduled job to be run according
|
||||
|
|
@ -14,7 +14,7 @@ import (
|
|||
// holding onto a next execution time safely in a concurrent environment.
|
||||
type Job struct {
|
||||
id uint64
|
||||
next atomics.Time
|
||||
next unsafe.Pointer // *time.Time
|
||||
timing Timing
|
||||
call func(time.Time)
|
||||
panic func(interface{})
|
||||
|
|
@ -33,9 +33,6 @@ func NewJob(fn func(now time.Time)) *Job {
|
|||
panic: func(i interface{}) { panic(i) },
|
||||
}
|
||||
|
||||
// Init next time ptr
|
||||
j.next.Store(zerotime)
|
||||
|
||||
return j
|
||||
}
|
||||
|
||||
|
|
@ -99,14 +96,20 @@ func (job *Job) OnPanic(fn func(interface{})) *Job {
|
|||
|
||||
// Next returns the next time this Job is expected to run.
|
||||
func (job *Job) Next() time.Time {
|
||||
return job.next.Load()
|
||||
return loadTime(&job.next)
|
||||
}
|
||||
|
||||
// Run will execute this Job and pass through given now time.
|
||||
func (job *Job) Run(now time.Time) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
switch r := recover(); {
|
||||
case r == nil:
|
||||
// no panic
|
||||
case job != nil &&
|
||||
job.panic != nil:
|
||||
job.panic(r)
|
||||
default:
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
job.call(now)
|
||||
|
|
@ -120,10 +123,21 @@ func (job *Job) String() string {
|
|||
buf.WriteString(strconv.FormatUint(job.id, 10))
|
||||
buf.WriteByte(' ')
|
||||
buf.WriteString("next=")
|
||||
buf.WriteString(job.next.Load().Format(time.StampMicro))
|
||||
buf.WriteString(loadTime(&job.next).Format(time.StampMicro))
|
||||
buf.WriteByte(' ')
|
||||
buf.WriteString("timing=")
|
||||
buf.WriteString(reflect.TypeOf(job.timing).String())
|
||||
buf.WriteByte('}')
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func loadTime(p *unsafe.Pointer) time.Time {
|
||||
if p := atomic.LoadPointer(p); p != nil {
|
||||
return *(*time.Time)(p)
|
||||
}
|
||||
return zerotime
|
||||
}
|
||||
|
||||
func storeTime(p *unsafe.Pointer, t time.Time) {
|
||||
atomic.StorePointer(p, unsafe.Pointer(&t))
|
||||
}
|
||||
|
|
|
|||
4
vendor/codeberg.org/gruf/go-sched/scheduler.go
generated
vendored
4
vendor/codeberg.org/gruf/go-sched/scheduler.go
generated
vendored
|
|
@ -225,7 +225,7 @@ func (sch *Scheduler) handle(v interface{}) {
|
|||
|
||||
// Update the next call time
|
||||
next := v.timing.Next(now)
|
||||
v.next.Store(next)
|
||||
storeTime(&v.next, next)
|
||||
|
||||
// Append this job to queued
|
||||
sch.jobs = append(sch.jobs, v)
|
||||
|
|
@ -261,7 +261,7 @@ func (sch *Scheduler) schedule(now time.Time) {
|
|||
|
||||
// Update the next call time
|
||||
next := job.timing.Next(now)
|
||||
job.next.Store(next)
|
||||
storeTime(&job.next, next)
|
||||
|
||||
if next.IsZero() {
|
||||
// Zero time, this job is done and can be dropped
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue