Skip to content

Commit

Permalink
messenger: make maxHandlers configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
samos123 committed Apr 6, 2024
1 parent aff7a32 commit 8f076e4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
23 changes: 18 additions & 5 deletions cmd/lingo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"log"
"net/http"
"os"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -94,18 +95,29 @@ func run() error {
}

type messengerURLPair struct {
requests string
responses string
requests string
responses string
maxHandlers int
}
var messengerURLPairs []messengerURLPair
for _, s := range cfg.MessengerURLs {
parts := strings.Split(s, "|")
if len(parts) != 2 {
if len(parts) != 2 && len(parts) != 3 {
return fmt.Errorf("invalid subscription URL: %q", s)
}
var maxHandlers int = 1000
var err error
if len(parts) == 3 {
maxHandlers, err = strconv.Atoi(parts[2])
if err != nil {
return fmt.Errorf("error converting messenger URL maxHandlers string %v to int: %w",
parts[2], err)
}
}
messengerURLPairs = append(messengerURLPairs, messengerURLPair{
requests: parts[0],
responses: parts[1],
requests: parts[0],
responses: parts[1],
maxHandlers: maxHandlers,
})
}

Expand Down Expand Up @@ -196,6 +208,7 @@ func run() error {
ctx,
msgURL.requests,
msgURL.responses,
msgURL.maxHandlers,
deploymentManager,
endpointManager,
queueManager,
Expand Down
3 changes: 2 additions & 1 deletion pkg/messenger/messager.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewMessenger(
ctx context.Context,
requestsURL string,
responsesURL string,
maxHandlers int,
deployments DeploymentManager,
endpoints EndpointManager,
queues QueueManager,
Expand All @@ -58,7 +59,7 @@ func NewMessenger(
HTTPC: httpClient,
requests: requests,
responses: responses,
MaxHandlers: 1000,
MaxHandlers: maxHandlers,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions tests/integration/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestMain(m *testing.M) {
testCtx,
memRequestsURL,
memResponsesURL,
1000,
deploymentManager,
endpointManager,
queueManager,
Expand Down

0 comments on commit 8f076e4

Please sign in to comment.