-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathexample.go
56 lines (45 loc) · 1.6 KB
/
example.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
package main
import (
"fmt"
"time"
"github.com/prashantgupta24/activity-tracker/internal/pkg/logging"
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
)
func main() {
logger := logging.New()
heartbeatInterval := 60 //value always in seconds
workerInterval := 4 //seconds
activityTracker := &tracker.Instance{
HeartbeatInterval: heartbeatInterval,
WorkerInterval: workerInterval,
LogLevel: logging.Info,
}
//This starts the tracker for all handlers. It gives you a channel
//which you can listen to for heartbeat objects
heartbeatCh := activityTracker.Start()
// //if you only want to track certain handlers, you can use StartWithhandlers
// heartbeatCh := activityTracker.StartWithHandlers(handler.MouseClickHandler(),
// handler.MouseCursorHandler())
loopTime := 2
timeToKill := time.NewTicker(time.Second * time.Duration((heartbeatInterval*loopTime)+1))
logger.Infof("starting activity tracker with %vs heartbeat and %vs worker interval ...", heartbeatInterval, workerInterval)
for {
select {
case heartbeat := <-heartbeatCh:
if !heartbeat.WasAnyActivity {
logger.Infof("no activity detected in the last %v seconds\n\n\n", int(heartbeatInterval))
} else {
logger.Infof("activity detected in the last %v seconds.", int(heartbeatInterval))
logger.Infof("Activity type:\n")
for activityType, times := range heartbeat.ActivityMap {
logger.Infof("activityType : %v times: %v\n", activityType, len(times))
}
fmt.Printf("\n\n\n")
}
case <-timeToKill.C:
logger.Infof("time to kill app")
activityTracker.Quit()
return
}
}
}