-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.go
More file actions
78 lines (69 loc) · 2.3 KB
/
common.go
File metadata and controls
78 lines (69 loc) · 2.3 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package goflower
import (
"time"
"github.com/google/uuid"
)
// gossipDeliveryInfo represents the delivery information for a gossip message.
type gossipDeliveryInfo struct {
Exchange string `json:"exchange"`
RoutingKey string `json:"routing_key"`
}
// gossipProperties represents the properties of a gossip message.
type gossipProperties struct {
DeliveryMode int `json:"delivery_mode"`
DeliveryInfo gossipDeliveryInfo `json:"delivery_info"`
Priority int `json:"priority"`
BodyEncoding string `json:"body_encoding"`
DeliveryTag string `json:"delivery_tag"`
}
// gossipHeaders represents the headers of a gossip message.
type gossipHeaders struct {
Hostname string `json:"hostname"`
}
// gossipEnvelope represents the envelope of a gossip message.
type gossipEnvelope struct {
Body string `json:"body"`
ContentEncoding string `json:"content-encoding"`
ContentType string `json:"content-type"`
Headers gossipHeaders `json:"headers"`
Properties gossipProperties `json:"properties"`
}
// gossipHeartbeatBody represents the body of a gossip heartbeat message.
type gossipHeartbeatBody struct {
Hostname string `json:"hostname"`
Utcoffset int `json:"utcoffset"`
Pid int `json:"pid"`
Clock int `json:"clock"`
Freq float64 `json:"freq"`
Active int `json:"active"`
Processed int `json:"processed"`
Loadavg []float64 `json:"loadavg"`
SwIdent string `json:"sw_ident"`
SwVer string `json:"sw_ver"`
SwSys string `json:"sw_sys"`
Timestamp float64 `json:"timestamp"`
Type string `json:"type"`
}
// createDefaultEnvelope creates a default gossipEnvelope with preset values.
func createDefaultEnvelope(hostname string) gossipEnvelope {
return gossipEnvelope{
ContentEncoding: "utf-8",
ContentType: "application/json",
Headers: gossipHeaders{
Hostname: hostname,
},
Properties: gossipProperties{
DeliveryMode: 1,
DeliveryInfo: gossipDeliveryInfo{
Exchange: "celeryev",
RoutingKey: "CHANGE_ME",
},
Priority: 0,
BodyEncoding: "base64",
DeliveryTag: uuid.NewString(),
},
}
}
func timestampFromTime(now time.Time) float64 {
return float64(now.UnixNano()) / float64(time.Second)
}