forked from NdoleStudio/httpsms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheartbeat_monitor.go
More file actions
29 lines (24 loc) · 1.23 KB
/
Copy pathheartbeat_monitor.go
File metadata and controls
29 lines (24 loc) · 1.23 KB
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
package entities
import (
"time"
"github.com/google/uuid"
)
// HeartbeatMonitor is used to monitor heartbeats of a phone
type HeartbeatMonitor struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;type:uuid;" bson:"_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
PhoneID uuid.UUID `json:"phone_id" bson:"phone_id" example:"32343a19-da5e-4b1b-a767-3298a73703cb"`
UserID UserID `json:"user_id" bson:"user_id" example:"WB7DRDWrJZRGbYrv2CKGkqbzvqdC"`
QueueID string `json:"queue_id" bson:"queue_id" example:"0360259236613675274"`
Owner string `json:"owner" bson:"owner" example:"+18005550199"`
PhoneOnline bool `json:"phone_online" bson:"phone_online" example:"true" default:"true"`
CreatedAt time.Time `json:"created_at" bson:"created_at" example:"2022-06-05T14:26:02.302718+03:00"`
UpdatedAt time.Time `json:"updated_at" bson:"updated_at" example:"2022-06-05T14:26:10.303278+03:00"`
}
// RequiresCheck returns true if the heartbeat monitor requires a check
func (h *HeartbeatMonitor) RequiresCheck() bool {
return h.UpdatedAt.Add(2 * time.Hour).Before(time.Now())
}
// PhoneIsOffline returns true if the phone is offline
func (h *HeartbeatMonitor) PhoneIsOffline() bool {
return !h.PhoneOnline
}