Merge remote-tracking branch 'upstream/v2' into v2
This commit is contained in:
+72
-13
@@ -367,8 +367,6 @@ func ExampleScheduler_removeByTags() {
|
||||
)
|
||||
fmt.Println(len(s.Jobs()))
|
||||
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
|
||||
s.RemoveByTags("tag1", "tag2")
|
||||
|
||||
fmt.Println(len(s.Jobs()))
|
||||
@@ -391,7 +389,6 @@ func ExampleScheduler_removeJob() {
|
||||
)
|
||||
|
||||
fmt.Println(len(s.Jobs()))
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
|
||||
_ = s.RemoveJob(j.ID())
|
||||
|
||||
@@ -519,7 +516,7 @@ func ExampleWithClock() {
|
||||
}
|
||||
|
||||
func ExampleWithDistributedElector() {
|
||||
//var _ Elector = (*myElector)(nil)
|
||||
//var _ gocron.Elector = (*myElector)(nil)
|
||||
//
|
||||
//type myElector struct{}
|
||||
//
|
||||
@@ -527,15 +524,15 @@ func ExampleWithDistributedElector() {
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//elector := myElector{}
|
||||
//elector := &myElector{}
|
||||
//
|
||||
//_, _ = NewScheduler(
|
||||
// WithDistributedElector(elector),
|
||||
//_, _ = gocron.NewScheduler(
|
||||
// gocron.WithDistributedElector(elector),
|
||||
//)
|
||||
}
|
||||
|
||||
func ExampleWithDistributedLocker() {
|
||||
//var _ Locker = (*myLocker)(nil)
|
||||
//var _ gocron.Locker = (*myLocker)(nil)
|
||||
//
|
||||
//type myLocker struct{}
|
||||
//
|
||||
@@ -552,10 +549,10 @@ func ExampleWithDistributedLocker() {
|
||||
// return nil
|
||||
//}
|
||||
//
|
||||
//locker := myLocker{}
|
||||
//locker := &myLocker{}
|
||||
//
|
||||
//_, _ = NewScheduler(
|
||||
// WithDistributedLocker(locker),
|
||||
//_, _ = gocron.NewScheduler(
|
||||
// gocron.WithDistributedLocker(locker),
|
||||
//)
|
||||
}
|
||||
|
||||
@@ -664,8 +661,8 @@ func ExampleWithLimitedRuns() {
|
||||
s.Start()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
fmt.Printf("no jobs in scheduler: %v\n", s.Jobs())
|
||||
_ = s.StopJobs()
|
||||
fmt.Printf("no jobs in scheduler: %v\n", s.Jobs())
|
||||
// Output:
|
||||
// one, 2
|
||||
// no jobs in scheduler: []
|
||||
@@ -687,6 +684,69 @@ func ExampleWithLogger() {
|
||||
)
|
||||
}
|
||||
|
||||
func ExampleWithMonitor() {
|
||||
//type exampleMonitor struct {
|
||||
// mu sync.Mutex
|
||||
// counter map[string]int
|
||||
// time map[string][]time.Duration
|
||||
//}
|
||||
//
|
||||
//func newExampleMonitor() *exampleMonitor {
|
||||
// return &exampleMonitor{
|
||||
// counter: make(map[string]int),
|
||||
// time: make(map[string][]time.Duration),
|
||||
//}
|
||||
//}
|
||||
//
|
||||
//func (t *exampleMonitor) IncrementJob(_ uuid.UUID, name string, _ []string, _ JobStatus) {
|
||||
// t.mu.Lock()
|
||||
// defer t.mu.Unlock()
|
||||
// _, ok := t.counter[name]
|
||||
// if !ok {
|
||||
// t.counter[name] = 0
|
||||
// }
|
||||
// t.counter[name]++
|
||||
//}
|
||||
//
|
||||
//func (t *exampleMonitor) RecordJobTiming(startTime, endTime time.Time, _ uuid.UUID, name string, _ []string) {
|
||||
// t.mu.Lock()
|
||||
// defer t.mu.Unlock()
|
||||
// _, ok := t.time[name]
|
||||
// if !ok {
|
||||
// t.time[name] = make([]time.Duration, 0)
|
||||
// }
|
||||
// t.time[name] = append(t.time[name], endTime.Sub(startTime))
|
||||
//}
|
||||
//
|
||||
//monitor := newExampleMonitor()
|
||||
//s, _ := NewScheduler(
|
||||
// WithMonitor(monitor),
|
||||
//)
|
||||
//name := "example"
|
||||
//_, _ = s.NewJob(
|
||||
// DurationJob(
|
||||
// time.Second,
|
||||
// ),
|
||||
// NewTask(
|
||||
// func() {
|
||||
// time.Sleep(1 * time.Second)
|
||||
// },
|
||||
// ),
|
||||
// WithName(name),
|
||||
// WithStartAt(
|
||||
// WithStartImmediately(),
|
||||
// ),
|
||||
//)
|
||||
//s.Start()
|
||||
//time.Sleep(5 * time.Second)
|
||||
//_ = s.Shutdown()
|
||||
//
|
||||
//fmt.Printf("Job %q total execute count: %d\n", name, monitor.counter[name])
|
||||
//for i, val := range monitor.time[name] {
|
||||
// fmt.Printf("Job %q execute #%d elapsed %.4f seconds\n", name, i+1, val.Seconds())
|
||||
//}
|
||||
}
|
||||
|
||||
func ExampleWithName() {
|
||||
s, _ := NewScheduler()
|
||||
defer func() { _ = s.Shutdown() }()
|
||||
@@ -748,7 +808,6 @@ func ExampleWithStartAt() {
|
||||
),
|
||||
)
|
||||
s.Start()
|
||||
time.Sleep(20 * time.Millisecond)
|
||||
|
||||
next, _ := j.NextRun()
|
||||
fmt.Println(next)
|
||||
|
||||
Reference in New Issue
Block a user