-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathevent_timing.go
More file actions
40 lines (35 loc) · 1.01 KB
/
event_timing.go
File metadata and controls
40 lines (35 loc) · 1.01 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
package agentremote
import (
"time"
"github.com/beeper/agentremote/pkg/shared/backfillutil"
)
// EventTiming carries the explicit timestamp and stream order for a live event.
type EventTiming struct {
Timestamp time.Time
StreamOrder int64
}
// ResolveEventTiming fills in missing live-event timing metadata using the
// shared backfill stream-order semantics.
func ResolveEventTiming(timestamp time.Time, streamOrder int64) EventTiming {
if timestamp.IsZero() {
timestamp = time.Now()
}
if streamOrder == 0 {
streamOrder = backfillutil.NextStreamOrder(0, timestamp)
}
return EventTiming{
Timestamp: timestamp,
StreamOrder: streamOrder,
}
}
// NextEventTiming allocates the next strictly increasing stream order for a
// sequence of related live events.
func NextEventTiming(lastStreamOrder int64, timestamp time.Time) EventTiming {
if timestamp.IsZero() {
timestamp = time.Now()
}
return EventTiming{
Timestamp: timestamp,
StreamOrder: backfillutil.NextStreamOrder(lastStreamOrder, timestamp),
}
}