WIP
This commit is contained in:
parent
8de8818516
commit
c554ccee83
|
@ -219,7 +219,19 @@ func (b *GethStatusBackend) ToggleCentralizedMetrics(isEnabled bool) error {
|
|||
return errors.New("centralized metrics nil")
|
||||
}
|
||||
|
||||
return b.centralizedMetrics.ToggleEnabled(isEnabled)
|
||||
var err error
|
||||
if isEnabled {
|
||||
if !b.centralizedMetrics.IsRunning() {
|
||||
// it was stopped, we need to recreate service
|
||||
fmt.Println("!!! restart")
|
||||
b.centralizedMetrics = centralizedmetrics.NewDefaultMetricService(b.multiaccountsDB.DB())
|
||||
}
|
||||
err = b.centralizedMetrics.Start()
|
||||
} else {
|
||||
err = b.centralizedMetrics.Stop()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) AddCentralizedMetric(metric centralizedmetricscommon.Metric) error {
|
||||
|
@ -227,7 +239,6 @@ func (b *GethStatusBackend) AddCentralizedMetric(metric centralizedmetricscommon
|
|||
return errors.New("centralized metrics nil")
|
||||
}
|
||||
return b.centralizedMetrics.AddMetric(metric)
|
||||
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) GetAccounts() ([]multiaccounts.Account, error) {
|
||||
|
|
|
@ -50,9 +50,17 @@ func NewMetricService(repository MetricRepository, processor common.MetricProces
|
|||
}
|
||||
}
|
||||
|
||||
func (s *MetricService) Start() {
|
||||
func (s *MetricService) IsRunning() bool {
|
||||
return s.started
|
||||
}
|
||||
|
||||
func (s *MetricService) Start() error {
|
||||
if s.started {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
err := s.repository.ToggleEnabled(true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.wg.Add(1)
|
||||
s.started = true
|
||||
|
@ -67,16 +75,22 @@ func (s *MetricService) Start() {
|
|||
}
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MetricService) Stop() {
|
||||
func (s *MetricService) Stop() error {
|
||||
if !s.started {
|
||||
return
|
||||
return nil
|
||||
}
|
||||
err := s.repository.ToggleEnabled(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.ticker.Stop()
|
||||
s.done <- true
|
||||
s.wg.Wait()
|
||||
s.started = false
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MetricService) EnsureStarted() error {
|
||||
|
@ -94,19 +108,6 @@ func (s *MetricService) Info() (*MetricsInfo, error) {
|
|||
return s.repository.Info()
|
||||
}
|
||||
|
||||
func (s *MetricService) ToggleEnabled(isEnabled bool) error {
|
||||
err := s.repository.ToggleEnabled(isEnabled)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isEnabled {
|
||||
s.Start()
|
||||
} else {
|
||||
s.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MetricService) AddMetric(metric common.Metric) error {
|
||||
return s.repository.Add(metric)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue