1
0
Fork 0

HTTP Request timeout to avoid issues when services are down

This commit is contained in:
Michał Rudowicz 2025-01-03 23:39:32 +01:00
parent e0fe26c41b
commit ba5e74d3c6
1 changed files with 10 additions and 2 deletions

View File

@ -8,12 +8,14 @@ import (
"log"
"net/http"
"sync"
"time"
"git.sr.ht/~michalr/go-satel"
)
const (
NotificationPartitionIndex = 0
httpTimeout = 1 * time.Second
)
type Sender interface {
@ -61,7 +63,10 @@ func doHttpNotification(url string, logger *log.Logger, wg *sync.WaitGroup) {
}
req, err := http.NewRequest(http.MethodPost, url, nil)
res, err := http.DefaultClient.Do(req)
client := http.Client{
Timeout: httpTimeout,
}
res, err := client.Do(req)
if err != nil {
logger.Print("Could not POST ", url, ": ", err)
return
@ -139,7 +144,10 @@ func SendToMatterbridge(events <-chan GenericMessage, s SatelNameGetter, config
}
req, err := http.NewRequest(http.MethodPost, matterbridgeConfig.URI, bytes.NewBuffer(body))
req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", matterbridgeConfig.Token)}
res, err := http.DefaultClient.Do(req)
client := http.Client{
Timeout: httpTimeout,
}
res, err := client.Do(req)
if err != nil {
logger.Print("Could not POST ", matterbridgeConfig.URI, ": ", err)
return