From 51bc5b04e1758627ac84e2234e864279cbd159c2 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Sat, 12 Jul 2014 17:42:04 +0700 Subject: [PATCH] More transparent writes --- storage.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/storage.go b/storage.go index 43858b0..9ee1da4 100644 --- a/storage.go +++ b/storage.go @@ -26,14 +26,16 @@ func SetupStorage() { func PersistMessages() { for { - payload := <-saver - i := payload.Queue.Counter.Write + 1 - key := NewKey(payload.Queue.Name, i) + p := <-saver - if err := storage.Set(key, payload.Message); err != nil { - rollbar.Error("error", err) - } else { - payload.Queue.Counter.Incr() - } + p.Queue.Counter.Write(func(i uint) bool { + key := NewKey(p.Queue.Name, i) + err := storage.Set(key, p.Message) + if err != nil { + Error(err, "Failed to write %d bytes to record '%s'", len(p.Message), key) + } + + return (err != nil) + }) } }