Skip to content

Commit

Permalink
Make kannel channel paused when we get Queued message in response
Browse files Browse the repository at this point in the history
  • Loading branch information
norkans7 committed Dec 12, 2023
1 parent 86ae080 commit 439fb3b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions handlers/kannel/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kannel

import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
Expand Down Expand Up @@ -200,10 +201,22 @@ func (h *handler) Send(ctx context.Context, msg courier.MsgOut, clog *courier.Ch
}

var resp *http.Response
var respBody []byte
if verifySSL {
resp, _, err = h.RequestHTTP(req, clog)
resp, respBody, err = h.RequestHTTP(req, clog)
} else {
resp, _, err = h.RequestHTTPInsecure(req, clog)
resp, respBody, err = h.RequestHTTPInsecure(req, clog)
}

if strings.Contains(string(respBody), "Queued") {
rc := h.Backend().RedisPool().Get()
defer rc.Close()
rateLimitKey := fmt.Sprintf("rate_limit:%s", msg.Channel().UUID())
rc.Do("SET", rateLimitKey, "engaged")

// We pause sending 30 seconds so the connection to the SMSC is reset
rc.Do("EXPIRE", rateLimitKey, 30)
return nil, errors.New("received Queued response from kannel, we'll pause sending to empty the queue")

Check warning on line 219 in handlers/kannel/handler.go

View check run for this annotation

Codecov / codecov/patch

handlers/kannel/handler.go#L212-L219

Added lines #L212 - L219 were not covered by tests
}

status := h.Backend().NewStatusUpdate(msg.Channel(), msg.ID(), courier.MsgStatusErrored, clog)
Expand Down

0 comments on commit 439fb3b

Please sign in to comment.