Skip to content

Commit 70c2de0

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

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

office365/main.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,26 @@ 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.LoginUrl); err != nil {
2831
utils.Logger.ErrorF("External connection failure detected: %v", err)
2932
}
3033

31-
et := st.Add(299 * time.Second)
32-
startTime := st.UTC().Format("2006-01-02T15:04:05")
33-
endTime := et.UTC().Format("2006-01-02T15:04:05")
34+
endTime := startTime.Add(299 * time.Second).UTC()
35+
startTimeStr := startTime.Format("2006-01-02T15:04:05")
36+
endTimeStr := endTime.Format("2006-01-02T15:04:05")
3437

3538
utils.Logger.Info("syncing logs from %s to %s", startTime, endTime)
3639

3740
moduleConfig, err := client.GetUTMConfig(enum.O365)
3841
if err != nil {
3942
if strings.Contains(err.Error(), "invalid character '<'") {
40-
time.Sleep(time.Second * delayCheck)
43+
startTime = endTime.Add(time.Second)
4144
continue
4245
}
4346
if (err.Error() != "") && (err.Error() != " ") {
@@ -46,9 +49,7 @@ func main() {
4649
utils.Logger.Info("program not configured yet")
4750
}
4851

49-
time.Sleep(time.Second * delayCheck)
50-
51-
st = et.Add(1)
52+
startTime = endTime.Add(time.Second)
5253

5354
continue
5455
}
@@ -72,7 +73,7 @@ func main() {
7273
}
7374

7475
if !skip {
75-
processor.PullLogs(startTime, endTime, group)
76+
processor.PullLogs(startTimeStr, endTimeStr, group)
7677
}
7778

7879
wg.Done()
@@ -83,8 +84,6 @@ func main() {
8384

8485
utils.Logger.Info("sync complete waiting %d seconds", delayCheck)
8586

86-
time.Sleep(time.Second * delayCheck)
87-
88-
st = et.Add(1)
87+
startTime = endTime.Add(time.Second)
8988
}
9089
}

0 commit comments

Comments
 (0)