-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathheartbeat.go
41 lines (35 loc) · 933 Bytes
/
heartbeat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package scheduled
import (
"net/http"
"time"
"github.com/bwmarrin/discordgo"
"github.com/ritsec/ops-bot-iii/config"
"github.com/ritsec/ops-bot-iii/logging"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
var (
// HeartbeatURL is the URL to send the heartbeat to
heartbeatURL string = config.GetString("commands.heartbeat.url")
)
// Heartbeat is a scheduled task that sends a heartbeat to the push-based life check
func Heartbeat(s *discordgo.Session, quit chan interface{}) error {
ticker := time.NewTicker(10 * time.Second)
for {
select {
case <-quit:
return nil
case <-ticker.C:
span := tracer.StartSpan(
"commands.scheduled.heartbeat:Heartbeat",
tracer.ResourceName("Scheduled.Heartbeat"),
)
_, err := http.Get(heartbeatURL)
if err != nil {
logging.Error(s, err.Error(), nil, span)
} else {
logging.DebugLow(s, "Heartbeat sent", nil, span)
}
span.Finish()
}
}
}