Skip to content

refactor: allow services to be initialized serially #2021

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

Open
wants to merge 1 commit into
base: reboot
Choose a base branch
from

Conversation

sthaha
Copy link
Collaborator

@sthaha sthaha commented Apr 19, 2025

This commit modifies the start up behavior. It refactors the service lifecycle management, replacing the Start and Stop methods with

  • Init: used to initiliaze a service and can assume it isn't called from go routines and must be called before Run.
  • Run: Runs the service and blocks until context is cancelled or an error is encountered
  • Shutdown: method is the cleanup and indicates that you can't call Run after Shutdown.

This change aims to separate initialization which is run serially and allows services to initialize without worrying about thread-safety. I.E. Its okay for an Init() to call another Init().

Thus, this change separates initialization, runtime, and cleanup phases for better clarity and control.

Tests are updated keep up with the change.

This commit modifies the start up behavior. It refactors the service lifecycle
management, replacing the Start and Stop methods with
* Init: used to initiliaze a service and can assume it isn't called from
  go routines
* Run: Runs the service and blocks until context is cancelled or an
  error is encountered
* `Shutdown`:  methods is the cleanup and indicates that you can't call
  `Run` after `Shutdown`.

This change aims to separate initialization which is run serially and allows
services to initialize without worrying about thread-safety.
I.E. Its okay for an Init() to call another Init().

Thus this change separates initialization, runtime, and cleanup phases for better
clarity and control.

Tests are updated keep up with the change.

Signed-off-by: Sunil Thaha <[email protected]>
@sthaha sthaha added the refactor Code refactoring without changing functionality label Apr 19, 2025
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 78.78788% with 7 lines in your changes missing coverage. Please review.

Project coverage is 90.68%. Comparing base (1341ea9) to head (87e9295).

Files with missing lines Patch % Lines
internal/monitor/monitor.go 60.00% 3 Missing and 1 partial ⚠️
internal/device/fake_cpu_power_meter.go 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           reboot    #2021      +/-   ##
==========================================
- Coverage   91.50%   90.68%   -0.82%     
==========================================
  Files          17       17              
  Lines        1000     1009       +9     
==========================================
  Hits          915      915              
- Misses         66       75       +9     
  Partials       19       19              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code refactoring without changing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant