HTTP Request timeout to avoid issues when services are down
This commit is contained in:
parent
e0fe26c41b
commit
ba5e74d3c6
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue