Feature: Faster start & stop times (#648)

* Updates starting and stopping routines to be a bit more parallel with less waiting required

* Removes stop, removes debugging output

* linting and test fixes

* Add extra kill switch for exiting on exchange loading delay

* Fixes fun math

* breaks loop instead of switch. Moves param warns higher

* Removes unceccary gos. passes in cfg to remove data race

* Removes os signal processing. Fixes bad master merge
This commit is contained in:
Scott
2021-03-23 10:18:57 +11:00
committed by GitHub
parent 46f71952f9
commit 3c72a199f2
18 changed files with 209 additions and 200 deletions

View File

@@ -1,18 +1,18 @@
package engine
import (
"errors"
"fmt"
"sync/atomic"
"github.com/thrasher-corp/gocryptotrader/config"
"github.com/thrasher-corp/gocryptotrader/connchecker"
"github.com/thrasher-corp/gocryptotrader/engine/subsystem"
"github.com/thrasher-corp/gocryptotrader/log"
)
// connectionManager manages the connchecker
type connectionManager struct {
started int32
stopped int32
conn *connchecker.Checker
}
@@ -23,8 +23,8 @@ func (c *connectionManager) Started() bool {
// Start starts an instance of the connection manager
func (c *connectionManager) Start(conf *config.ConnectionMonitorConfig) error {
if atomic.AddInt32(&c.started, 1) != 1 {
return errors.New("connection manager already started")
if !atomic.CompareAndSwapInt32(&c.started, 0, 1) {
return fmt.Errorf("connection manager %w", subsystem.ErrSubSystemAlreadyStarted)
}
log.Debugln(log.ConnectionMgr, "Connection manager starting...")
@@ -44,17 +44,14 @@ func (c *connectionManager) Start(conf *config.ConnectionMonitorConfig) error {
// Stop stops the connection manager
func (c *connectionManager) Stop() error {
if atomic.LoadInt32(&c.started) == 0 {
return errors.New("connection manager not started")
}
if atomic.AddInt32(&c.stopped, 1) != 1 {
return errors.New("connection manager is already stopped")
return fmt.Errorf("connection manager %w", subsystem.ErrSubSystemNotStarted)
}
defer func() {
atomic.CompareAndSwapInt32(&c.started, 1, 0)
}()
log.Debugln(log.ConnectionMgr, "Connection manager shutting down...")
c.conn.Shutdown()
atomic.CompareAndSwapInt32(&c.stopped, 1, 0)
atomic.CompareAndSwapInt32(&c.started, 1, 0)
log.Debugln(log.ConnectionMgr, "Connection manager stopped.")
return nil
}