-
Notifications
You must be signed in to change notification settings - Fork 922
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
introduce entity that will keep info about services current state and integrate it into DASer and Syncer #725
Conversation
Codecov Report
@@ Coverage Diff @@
## main #725 +/- ##
==========================================
- Coverage 52.55% 52.52% -0.03%
==========================================
Files 112 113 +1
Lines 6405 6425 +20
==========================================
+ Hits 3366 3375 +9
- Misses 2688 2696 +8
- Partials 351 354 +3
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making Service like this libs/service.Service
and usage like :
type Syncer struct{
service.Service
...
}
func (s *Syncer) Stop(context.Context) error {
if s.state.State() == service.Stopped {
return nil
}
defer s.state.SetState(service.Stopped)
}
WDYT?
Other thoughts:
|
@Wondertan, no other plans except provided. I do not think that it's overengineering. It allows to re-use this structure in different services and provides simple aliases for On/Off state |
9623bb5
to
08f4472
Compare
Can you also rename the PR to something more appropriate? We already have a state service that accesses the State of the blockchain |
@@ -82,6 +86,11 @@ func (d *DASer) Start(context.Context) error { | |||
|
|||
// Stop stops sampling. | |||
func (d *DASer) Stop(ctx context.Context) error { | |||
if d.State() == service.Stopped { | |||
log.Debug("Daser is stopped") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.Debug("Daser is stopped") | |
log.Debug("DASer is stopped") |
|
||
// Service provides an interface to change an check service state | ||
type Service struct { | ||
state uint32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
state uint32 | |
state State |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case storing and loading state will be more complex:
* atomic.StoreUint32((*uint32)(&s.state), uint32(state))
* return State(atomic.LoadUint32((*uint32)(&s.state)))
IMO, better to leave uint32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then maybe the naming of state
here is inconsistent? s.state
seems to be a key for the state, not a state? If so, it it's 1) not clearly named or documented, and 2) should be uint64
, unless there's a very specific reason it must be a uint32
.
Closing this PR in favour of more priority tasks. |
Resolves #724