feat(client): implement exponential backoff retry for network errors
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -15,6 +16,7 @@ type config struct {
|
||||
ZarinHubUsername string
|
||||
ZarinHubPassword string
|
||||
ZarinHubTimeout time.Duration
|
||||
ZarinHubRetries int
|
||||
DatabasePath string
|
||||
}
|
||||
|
||||
@@ -44,6 +46,18 @@ func readConfig(getenv func(string) string) (config, error) {
|
||||
)
|
||||
}
|
||||
|
||||
retriesText := valueOrDefault(
|
||||
getenv("ZARINHUB_RETRIES"),
|
||||
"2",
|
||||
)
|
||||
|
||||
retries, err := strconv.Atoi(retriesText)
|
||||
if err != nil || retries < 0 {
|
||||
return config{}, fmt.Errorf(
|
||||
"ZARINHUB_RETRIES must be a non-negative integer",
|
||||
)
|
||||
}
|
||||
|
||||
return config{
|
||||
ServerAddr: valueOrDefault(
|
||||
getenv("SERVER_ADDR"),
|
||||
@@ -64,6 +78,7 @@ func readConfig(getenv func(string) string) (config, error) {
|
||||
ZarinHubUsername: username,
|
||||
ZarinHubPassword: password,
|
||||
ZarinHubTimeout: timeout,
|
||||
ZarinHubRetries: retries,
|
||||
DatabasePath: valueOrDefault(
|
||||
getenv("DATABASE_PATH"),
|
||||
"./card-to-iban.db",
|
||||
|
||||
Reference in New Issue
Block a user