Skip to content

Commit

Permalink
Tweaks in case of nil msg statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Jul 12, 2017
1 parent 0f3a96d commit d315636
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand All @@ -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)
}
}

Expand Down
10 changes: 6 additions & 4 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d315636

Please sign in to comment.