github.com/bshelton229/agent@v3.5.4+incompatible/api/heartbeats.go (about) 1 package api 2 3 import "time" 4 5 // HeartbeatsService handles communication with the ping related methods of the 6 // Buildkite Agent API. 7 type HeartbeatsService struct { 8 client *Client 9 } 10 11 // Heartbeat represents a Buildkite Agent API Heartbeat 12 type Heartbeat struct { 13 SentAt string `json:"sent_at"` 14 ReceivedAt string `json:"received_at,omitempty"` 15 } 16 17 // Heartbeats the API which keeps the agent connected to Buildkite 18 func (hs *HeartbeatsService) Beat() (*Heartbeat, *Response, error) { 19 // Include the current time in the heartbeat, and include the operating 20 // systems timezone. 21 heartbeat := &Heartbeat{SentAt: time.Now().Format(time.RFC3339Nano)} 22 23 req, err := hs.client.NewRequest("POST", "heartbeat", &heartbeat) 24 if err != nil { 25 return nil, nil, err 26 } 27 28 resp, err := hs.client.Do(req, heartbeat) 29 if err != nil { 30 return nil, resp, err 31 } 32 33 return heartbeat, resp, err 34 }