Skip to content

Commit

Permalink
feat(usage): add feature to ping immediately after PingCheck starts
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <niladri.halder26@gmail.com>
  • Loading branch information
niladrih committed Jun 19, 2024
1 parent cb13796 commit 5554773
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions usage/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,23 @@ const (
)

// PingCheck sends ping events to Google Analytics
func PingCheck(engineName, category string) {
func PingCheck(engineName, category string, pingImmediately bool) {
// Create a new usage field
u := New()
pingSender := u.CommonBuild(engineName).
InstallBuilder(true).
SetCategory(category)

if pingImmediately {
// Ping immediately.
pingSender.Send()
}

duration := getPingPeriod()
ticker := time.NewTicker(duration)
for range ticker.C {
u.CommonBuild(engineName).
InstallBuilder(true).
SetCategory(category).
Send()
// Ping periodically, starting at 'duration'.
pingSender.Send()
}
}

Expand Down

0 comments on commit 5554773

Please sign in to comment.