Create monitor for item acceptance/publishing
This commit is contained in:
44
monitor/item.go
Normal file
44
monitor/item.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user