Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
feat(check): add timeout
Browse files Browse the repository at this point in the history
add timeout

Signed-off-by: mritd <[email protected]>
  • Loading branch information
mritd committed Oct 16, 2018
1 parent 132f158 commit 196a23e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Config struct {
WebSites []string
Cron string
BeforeTime time.Duration
TimeOut time.Duration
}

func ExampleConfig() Config {
Expand All @@ -48,17 +49,21 @@ func ExampleConfig() Config {
},
Cron: "@every 1h",
BeforeTime: 7 * 24 * time.Hour,
TimeOut: 10 * time.Second,
}
}

func check(address string, beforeTime time.Duration) error {
func check(address string, beforeTime, timeout time.Duration) error {

logrus.Infof("Check website [%s]...", address)

tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
client := &http.Client{Transport: tr}
client := &http.Client{
Transport: tr,
Timeout: timeout,
}
resp, err := client.Get(address)
if !utils.CheckErr(err) {
return err
Expand Down Expand Up @@ -90,7 +95,7 @@ func Start() {
for _, website := range config.WebSites {
addr := website
c.AddFunc(config.Cron, func() {
err := check(addr, config.BeforeTime)
err := check(addr, config.BeforeTime, config.TimeOut)
if err != nil {
alarm.Alarm(err.Error())
}
Expand Down

0 comments on commit 196a23e

Please sign in to comment.