From d315636c069ea65fe12b9fd311d350b9e20ddbe0 Mon Sep 17 00:00:00 2001 From: Nic Pottier Date: Wed, 12 Jul 2017 15:14:52 -0500 Subject: [PATCH] Tweaks in case of nil msg statuses --- backend.go | 3 ++- backends/rapidpro/backend.go | 8 ++++---- sender.go | 10 ++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/backend.go b/backend.go index d29fbb221..eb949794b 100644 --- a/backend.go +++ b/backend.go @@ -51,7 +51,8 @@ type Backend interface { WasMsgSent(msg Msg) (bool, error) // MarkOutgoingMsgComplete marks the passed in message as having been processed. Note this should be called even in the case - // of errors during sending as it will manage the number of active workers per channel + // of errors during sending as it will manage the number of active workers per channel. The optional status parameter can be + // used to determine any sort of deduping of msg sends MarkOutgoingMsgComplete(Msg, MsgStatus) // Health returns a string describing any health problems the backend has, or empty string if all is well diff --git a/backends/rapidpro/backend.go b/backends/rapidpro/backend.go index dff646134..b7f5aca7d 100644 --- a/backends/rapidpro/backend.go +++ b/backends/rapidpro/backend.go @@ -98,7 +98,7 @@ func (b *backend) WasMsgSent(msg courier.Msg) (bool, error) { defer rc.Close() dateKey := fmt.Sprintf(sentSetName, time.Now().In(time.UTC).Format("2006_01_02")) - found, err := redis.Bool(rc.Do("SISMEMBER", dateKey, msg.ID().Int64)) + found, err := redis.Bool(rc.Do("isismember", dateKey, msg.ID().Int64)) if err != nil { return false, err } @@ -107,7 +107,7 @@ func (b *backend) WasMsgSent(msg courier.Msg) (bool, error) { } dateKey = fmt.Sprintf(sentSetName, time.Now().Add(time.Hour*-24).In(time.UTC).Format("2006_01_02")) - found, err = redis.Bool(rc.Do("SISMEMBER", dateKey, msg.ID().Int64)) + found, err = redis.Bool(rc.Do("sismember", dateKey, msg.ID().Int64)) return found, err } @@ -120,9 +120,9 @@ func (b *backend) MarkOutgoingMsgComplete(msg courier.Msg, status courier.MsgSta queue.MarkComplete(rc, msgQueueName, dbMsg.WorkerToken_) // mark as sent in redis as well if this was actually wired or sent - if status.Status() == courier.MsgSent || status.Status() == courier.MsgWired { + if status != nil && (status.Status() == courier.MsgSent || status.Status() == courier.MsgWired) { dateKey := fmt.Sprintf(sentSetName, time.Now().In(time.UTC).Format("2006_01_02")) - rc.Do("SADD", dateKey, msg.ID().Int64) + rc.Do("sadd", dateKey, msg.ID().Int64) } } diff --git a/sender.go b/sender.go index 3ca1b957a..bf875845e 100644 --- a/sender.go +++ b/sender.go @@ -175,10 +175,12 @@ func (w *Sender) Send() { } } - // record our status - err = backend.WriteMsgStatus(status) - if err != nil { - log.WithField("msgID", msg.ID().Int64).WithError(err).Info("error writing msg status") + // record our status if we have one + if status != nil { + err = backend.WriteMsgStatus(status) + if err != nil { + log.WithField("msgID", msg.ID().Int64).WithError(err).Info("error writing msg status") + } } // mark our send task as complete