Skip to content

Commit 4454c95

Browse files
committed
refactor(aws): Replace manual sleep with ticker for consistent polling
1 parent be9ef1a commit 4454c95

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

aws/main.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,33 @@ func main() {
2121
panelServ := configuration.GetPanelServiceName()
2222
client := utmconf.NewUTMClient(intKey, "http://"+panelServ)
2323

24-
st := time.Now().Add(-600 * time.Second)
24+
ticker := time.NewTicker(time.Second * delayCheck)
25+
defer ticker.Stop()
2526

26-
for {
27+
startTime := time.Now().Add(-600 * time.Second).UTC()
28+
29+
for range ticker.C {
2730
if err := utils.ConnectionChecker(configuration.URL_CHECK_CONNECTION); err != nil {
2831
utils.Logger.ErrorF("Failed to establish connection: %v", err)
2932
}
3033

31-
et := st.Add(299 * time.Second)
34+
endTime := startTime.Add(299 * time.Second).UTC()
35+
36+
utils.Logger.Info("syncing logs from %s to %s", startTime, endTime)
37+
3238
moduleConfig, err := client.GetUTMConfig(enum.AWS_IAM_USER)
3339
if err != nil {
3440
if strings.Contains(err.Error(), "invalid character '<'") {
3541
utils.Logger.LogF(100, "error getting configuration of the AWS module: %v", err)
36-
time.Sleep(time.Second * delayCheck)
42+
startTime = endTime.Add(time.Second)
3743
continue
3844
}
3945
if (err.Error() != "") && (err.Error() != " ") {
4046
utils.Logger.ErrorF("error getting configuration of the AWS module: %v", err)
4147
}
4248

4349
utils.Logger.Info("sync complete waiting %v seconds", delayCheck)
44-
time.Sleep(time.Second * delayCheck)
45-
st = et.Add(1)
50+
startTime = endTime.Add(time.Second)
4651
continue
4752
}
4853

@@ -62,7 +67,7 @@ func main() {
6267
}
6368

6469
if !skip {
65-
processor.PullLogs(st, et, group)
70+
processor.PullLogs(startTime, endTime, group)
6671
}
6772

6873
wg.Done()
@@ -71,7 +76,7 @@ func main() {
7176

7277
wg.Wait()
7378
utils.Logger.Info("sync complete waiting %d seconds", delayCheck)
74-
time.Sleep(time.Second * delayCheck)
75-
st = et.Add(1)
79+
80+
startTime = endTime.Add(time.Second)
7681
}
7782
}

0 commit comments

Comments
 (0)