-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
70 lines (62 loc) · 2.03 KB
/
util.go
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
package main
import (
"context"
"os"
"os/signal"
"reflect"
"syscall"
"time"
log "github.com/sirupsen/logrus"
)
func makeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}
func now() time.Time {
return time.Now().UTC()
}
// setupCloseHandler creates a 'listener' on a new goroutine which will notify the
// program if it receives an interrupt from the OS. We then handle this by calling
// our clean up procedure and exiting the program.
func setupCloseHandler(cancel context.CancelFunc) {
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
for {
select {
case <-c:
log.Debugf("SHUTDOWN: OS Interrupt received!")
// cancel highest level context for firestream
cancel()
// finalize metrics and print out stats before exit
//finalizeMetrics()
case <-shutdownFirestreamImmediately:
log.Debugf("shutdownFirestreamImmediately request recieved!")
// cancel highest level context for firestream
cancel()
// finalize metrics and print out stats before exit
//finalizeMetrics()
}
}
}
// help check for nil values and avoid panics w/ reflection
func IsNilInterface(i interface{}) bool {
return i == nil || reflect.ValueOf(i).IsNil()
}
// Return a time.Time object from a provided UTC epoch time as a float64
func nanoEpochTimeObject(ts float64) (time.Time, error) {
tsi := (int64(ts) * int64(time.Millisecond)) // Firebase takes seconds or nanoseconds not millis
keyDate := time.Unix(0, tsi).UTC()
return keyDate, nil
}
// Initialize global channels for use throughout Firestream
func initGlobalChannels() (ok bool) {
// request a navajo update immediately
navajoUpdater = make(chan bool)
// request shutdown sequence initate
shutdownFirestreamImmediately = make(chan bool)
// init report processing channels for Stream API Reports -> Firestore
firestoreAssembly = make(chan ReportDataStreamV1)
transponderReportsV1 = make(chan TransponderReportDataStreamV1)
videoReportsV1 = make(chan VideoReportDataStreamV1)
eldReportsV1 = make(chan EldReportDataStreamV1)
return ok
}