heartbeat.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. package heartbeat
  2. import (
  3. "time"
  4. )
  5. // HeartbeatEventName is used to represent the name of the heartbeat pipeline event to categorize for storage.
  6. const HeartbeatEventName string = "heartbeat"
  7. // Heartbeat is a payload struct that contains custom information and the timestamp of the heartbeat.
  8. type Heartbeat struct {
  9. Id string `json:"id"`
  10. Timestamp time.Time `json:"timestamp"`
  11. Uptime uint64 `json:"uptime"`
  12. Application string `json:"application"`
  13. Version string `json:"version"`
  14. Metadata map[string]any `json:"metadata,omitempty"`
  15. }
  16. // NewHeartbeat creates a new Heartbeat instance with the provided parameters.
  17. // The `id` is a unique identifier for the heartbeat, `timestamp` is the time of the heartbeat,
  18. // `uptime` is the uptime in seconds, `version` is the version of the heartbeat, and `metadata`
  19. // is a pointer to a generic type that can hold any additional information. Metadata _can_ be omitted
  20. // by passing `nil`.
  21. func NewHeartbeat(id string, timestamp time.Time, uptime uint64, application string, version string, metadata map[string]any) *Heartbeat {
  22. return &Heartbeat{
  23. Id: id,
  24. Timestamp: timestamp,
  25. Uptime: uptime,
  26. Application: application,
  27. Version: version,
  28. Metadata: metadata,
  29. }
  30. }