Create monitor for item acceptance/publishing

This commit is contained in:
Bel LaPointe
2018-10-08 13:30:08 -06:00
parent 49d95c150e
commit 45465680ae
4 changed files with 253 additions and 0 deletions

44
monitor/item.go Normal file
View 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
}