Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: periodic operations to use time.Ticker #978

Merged
merged 1 commit into from
Jan 29, 2025
Merged

Conversation

appleboy
Copy link
Contributor

  • Use time.Ticker instead of time.After for periodic operations in autoSave function
  • Use time.Ticker instead of time.After for periodic operations in monitor function

Summary

This PR includes the following changes:

  • Replaced time.After(interval) with time.NewTicker(interval) in both storage/store/store.go and watchdog/watchdog.go.
  • This change ensures that the automatic save and monitoring operations are executed regularly and that the ticker is properly stopped when the context is done.

- Use `time.Ticker` instead of `time.After` for periodic operations in `autoSave` function
- Use `time.Ticker` instead of `time.After` for periodic operations in `monitor` function

Signed-off-by: appleboy <[email protected]>
@appleboy
Copy link
Contributor Author

@TwiN Please take a look mirror changes.

@TwiN
Copy link
Owner

TwiN commented Jan 29, 2025

@appleboy Thank you very much for the optimization! If you find any other small issues like this, please don't hesitate to create a pull request.

I learned Go as I was building Gatus, so some of the older code is in dire need of love.

@TwiN TwiN merged commit 5b3e0c8 into TwiN:master Jan 29, 2025
1 check passed
Copy link

codecov bot commented Jan 29, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.87%. Comparing base (dd839be) to head (88aecb3).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #978   +/-   ##
=======================================
  Coverage   75.86%   75.87%           
=======================================
  Files          74       74           
  Lines        6758     6760    +2     
=======================================
+ Hits         5127     5129    +2     
  Misses       1325     1325           
  Partials      306      306           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@appleboy appleboy deleted the timer branch January 29, 2025 04:11
@appleboy
Copy link
Contributor Author

@TwiN

Sure, no problem. I also learned the Go language through writing a new project, Gorush. We can exchange more ideas in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants