Fix counter increment condition
This commit is contained in:
parent
da544b85b5
commit
bd561cd73a
3
queue.go
3
queue.go
|
@ -12,10 +12,11 @@ var (
|
|||
)
|
||||
|
||||
func (q *Queue) Push(msg Message) {
|
||||
saver <- Payload{
|
||||
p := Payload{
|
||||
Queue: q,
|
||||
Message: msg,
|
||||
}
|
||||
Persist(p)
|
||||
}
|
||||
|
||||
func (q *Queue) TryFetch() (Message, bool) {
|
||||
|
|
12
storage.go
12
storage.go
|
@ -16,8 +16,8 @@ type (
|
|||
)
|
||||
|
||||
var (
|
||||
storage = cabinet.New()
|
||||
saver = make(chan Payload, 1000)
|
||||
storage = cabinet.New()
|
||||
payloads = make(chan Payload, 1000)
|
||||
)
|
||||
|
||||
func NewKey(queue string, index uint) Key {
|
||||
|
@ -33,9 +33,13 @@ func SetupStorage() {
|
|||
}
|
||||
}
|
||||
|
||||
func Persist(p Payload) {
|
||||
payloads <- p
|
||||
}
|
||||
|
||||
func PersistMessages() {
|
||||
for {
|
||||
p := <-saver
|
||||
p := <-payloads
|
||||
|
||||
p.Queue.Counter.Write(func(i uint) bool {
|
||||
key := NewKey(p.Queue.Name, i)
|
||||
|
@ -44,7 +48,7 @@ func PersistMessages() {
|
|||
Error(err, "Failed to write %d bytes to record '%s'", len(p.Message), key)
|
||||
}
|
||||
|
||||
return (err != nil)
|
||||
return (err == nil)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue