forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 1
/
heartbeats.go
34 lines (27 loc) · 884 Bytes
/
heartbeats.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
package api
import "time"
// HeartbeatsService handles communication with the ping related methods of the
// Buildkite Agent API.
type HeartbeatsService struct {
client *Client
}
// Heartbeat represents a Buildkite Agent API Heartbeat
type Heartbeat struct {
SentAt string `json:"sent_at"`
ReceivedAt string `json:"received_at,omitempty"`
}
// Heartbeats the API which keeps the agent connected to Buildkite
func (hs *HeartbeatsService) Beat() (*Heartbeat, *Response, error) {
// Include the current time in the heartbeat, and include the operating
// systems timezone.
heartbeat := &Heartbeat{SentAt: time.Now().Format(time.RFC3339Nano)}
req, err := hs.client.NewRequest("POST", "heartbeat", &heartbeat)
if err != nil {
return nil, nil, err
}
resp, err := hs.client.Do(req, heartbeat)
if err != nil {
return nil, resp, err
}
return heartbeat, resp, err
}