fix: default gateway callback batching off

This commit is contained in:
hectorzhao
2026-08-26 13:59:21 +08:00
parent 4a17df78b8
commit 8170f727a3
5 changed files with 38 additions and 1 deletions
+5 -1
View File
@@ -95,7 +95,7 @@ func main() {
resultOutbox.Consumer = getenv("GATEWAY_SUBMIT_RESULT_CONSUMER", "gateway-1")
resultOutbox.APIBaseURL = callbackBaseURL
resultOutbox.Concurrency = positiveEnvInt("GATEWAY_SUBMIT_RESULT_WORKER_CONCURRENCY", 8)
resultOutbox.BatchEnabled = os.Getenv("GATEWAY_CALLBACK_BATCH_ENABLED") != "false"
resultOutbox.BatchEnabled = enabledEnv("GATEWAY_CALLBACK_BATCH_ENABLED")
resultOutbox.BatchSize = positiveEnvInt("GATEWAY_CALLBACK_BATCH_SIZE", 50)
resultOutbox.BatchWait = time.Duration(positiveEnvInt("GATEWAY_CALLBACK_BATCH_WAIT_MS", 10)) * time.Millisecond
resultOutbox.GatewayInstanceID = gatewayInstanceID
@@ -234,6 +234,10 @@ func positiveEnvInt(key string, fallback int) int {
return value
}
func enabledEnv(key string) bool {
return os.Getenv(key) == "true"
}
func hostname() string {
name, err := os.Hostname()
if err != nil || name == "" {
+23
View File
@@ -0,0 +1,23 @@
package main
import "testing"
func TestEnabledEnvRequiresExplicitTrue(t *testing.T) {
for _, testCase := range []struct {
name string
value string
want bool
}{
{name: "unset", want: false},
{name: "false", value: "false", want: false},
{name: "other value", value: "TRUE", want: false},
{name: "true", value: "true", want: true},
} {
t.Run(testCase.name, func(t *testing.T) {
t.Setenv("GATEWAY_CALLBACK_BATCH_ENABLED", testCase.value)
if got := enabledEnv("GATEWAY_CALLBACK_BATCH_ENABLED"); got != testCase.want {
t.Fatalf("enabledEnv() = %v, want %v", got, testCase.want)
}
})
}
}