Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed Aug 16, 2019
1 parent 682e260 commit a05e507
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions backends/rapidpro/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const chatbaseMessageType = "msg"
// our timeout for backend operations
const backendTimeout = time.Second * 20

// number of messages for loop detection
const msgLoopThreshold = 20

func init() {
courier.RegisterBackend("rapidpro", newBackend)
}
Expand Down Expand Up @@ -205,7 +208,7 @@ var luaMsgLoop = redis.NewScript(3, `-- KEYS: [key, contact_id, text]
-- create our new record with our updated count
record = string.format("%02d:%s", count, text)
-- write our new record witn updated count
-- write our new record with updated count
redis.call("hset", key, contact_id, record)
-- sets its expiration
Expand Down Expand Up @@ -234,7 +237,7 @@ func (b *backend) IsMsgLoop(ctx context.Context, msg courier.Msg) (bool, error)
return false, errors.Wrapf(err, "error while checking for msg loop")
}

if count >= 20 {
if count >= msgLoopThreshold {
return true, nil
}
return false, nil
Expand Down
4 changes: 2 additions & 2 deletions sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ func (w *Sender) sendMessage(msg Msg) {

// failing on a lookup isn't a halting problem but we should log it
if err != nil {
log.WithError(err).Warning("error looking up msg was sent")
log.WithError(err).Error("error looking up msg was sent")
}

// is this msg in a loop?
loop, err := backend.IsMsgLoop(sendCTX, msg)

// failing on loop lookup isn't permanent, but log
if err != nil {
log.WithError(err).Warning("error looking up msg loop")
log.WithError(err).Error("error looking up msg loop")
}

if sent {
Expand Down

0 comments on commit a05e507

Please sign in to comment.