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"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.sr.ht/~michalr/go-satel"
|
"git.sr.ht/~michalr/go-satel"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NotificationPartitionIndex = 0
|
NotificationPartitionIndex = 0
|
||||||
|
httpTimeout = 1 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sender interface {
|
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)
|
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 {
|
if err != nil {
|
||||||
logger.Print("Could not POST ", url, ": ", err)
|
logger.Print("Could not POST ", url, ": ", err)
|
||||||
return
|
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, err := http.NewRequest(http.MethodPost, matterbridgeConfig.URI, bytes.NewBuffer(body))
|
||||||
req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", matterbridgeConfig.Token)}
|
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 {
|
if err != nil {
|
||||||
logger.Print("Could not POST ", matterbridgeConfig.URI, ": ", err)
|
logger.Print("Could not POST ", matterbridgeConfig.URI, ": ", err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue