45 lines
719 B
Go
45 lines
719 B
Go
package monitor
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/golang-collections/go-datastructures/queue"
|
|
)
|
|
|
|
type Item struct {
|
|
url string
|
|
interval time.Duration
|
|
next time.Time
|
|
}
|
|
|
|
func NewItem(url string, interval time.Duration) *Item {
|
|
return &Item{
|
|
url: url,
|
|
interval: interval,
|
|
next: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (item *Item) Compare(other queue.Item) int {
|
|
j, ok := other.(*Item)
|
|
if !ok {
|
|
return 0
|
|
}
|
|
if item.next.Before(j.next) {
|
|
return -1
|
|
} else if item.next.After(j.next) {
|
|
return 1
|
|
}
|
|
if item.interval < j.interval {
|
|
return -1
|
|
} else if item.interval > j.interval {
|
|
return 1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
func (item *Item) increment() *Item {
|
|
item.next = time.Now().Add(item.interval)
|
|
return item
|
|
}
|