shared project
This commit is contained in:
parent
24aefd98aa
commit
515b618aba
31
queue.go
31
queue.go
|
@ -2,28 +2,27 @@ package queue
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
"time"
|
|
||||||
"loafle.com/overflow/agent_api/observer"
|
|
||||||
"github.com/prometheus/common/log"
|
"github.com/prometheus/common/log"
|
||||||
|
"loafle.com/overflow/agent_api/observer"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EventType int
|
type EventType int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
DATA_TYPE EventType = 0
|
||||||
DATA_TYPE EventType = 0
|
|
||||||
EVENT_TYPE EventType = 1
|
EVENT_TYPE EventType = 1
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type item struct {
|
type item struct {
|
||||||
value interface{}
|
value interface{}
|
||||||
priority int
|
priority int
|
||||||
}
|
}
|
||||||
|
|
||||||
type LoafleQueue struct {
|
type LoafleQueue struct {
|
||||||
items []*item
|
items []*item
|
||||||
queueType string
|
queueType string
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
|
|
||||||
eventChanel chan interface{}
|
eventChanel chan interface{}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +67,7 @@ func (lq *LoafleQueue) Pop() interface{} {
|
||||||
}
|
}
|
||||||
func (lq LoafleQueue) newItem(value interface{}) *item {
|
func (lq LoafleQueue) newItem(value interface{}) *item {
|
||||||
return &item{
|
return &item{
|
||||||
value:value,
|
value: value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,22 +85,22 @@ func (lq *LoafleQueue) Close() {
|
||||||
}
|
}
|
||||||
func NewLoafleQueue(eventType EventType, interval time.Duration) *LoafleQueue {
|
func NewLoafleQueue(eventType EventType, interval time.Duration) *LoafleQueue {
|
||||||
items := make([]*item, 0)
|
items := make([]*item, 0)
|
||||||
event := make(chan interface{},0)
|
event := make(chan interface{}, 0)
|
||||||
var tempType string
|
var tempType string
|
||||||
|
|
||||||
if eventType == DATA_TYPE {
|
if eventType == DATA_TYPE {
|
||||||
tempType = "DATA_TYPE"
|
tempType = "DATA_TYPE"
|
||||||
}else if eventType == EVENT_TYPE{
|
} else if eventType == EVENT_TYPE {
|
||||||
tempType = "EVENT_TYPE"
|
tempType = "EVENT_TYPE"
|
||||||
}else {
|
} else {
|
||||||
log.Fatal("Event Type Error")
|
log.Fatal("Event Type Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
lq := &LoafleQueue{
|
lq := &LoafleQueue{
|
||||||
items:items,
|
items: items,
|
||||||
queueType:tempType,
|
queueType: tempType,
|
||||||
interval:interval,
|
interval: interval,
|
||||||
eventChanel:event,
|
eventChanel: event,
|
||||||
}
|
}
|
||||||
|
|
||||||
observer.Add(lq.queueType, lq.eventChanel)
|
observer.Add(lq.queueType, lq.eventChanel)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user