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

@@ -2,17 +2,18 @@ package engine
import (
"errors"
"fmt"
"sync/atomic"
"github.com/thrasher-corp/gocryptotrader/communications"
"github.com/thrasher-corp/gocryptotrader/communications/base"
"github.com/thrasher-corp/gocryptotrader/engine/subsystem"
"github.com/thrasher-corp/gocryptotrader/log"
)
// commsManager starts the NTP manager
type commsManager struct {
started int32
stopped int32
shutdown chan struct{}
relayMsg chan base.Event
comms *communications.Communications
@@ -23,8 +24,8 @@ func (c *commsManager) Started() bool {
}
func (c *commsManager) Start() (err error) {
if atomic.AddInt32(&c.started, 1) != 1 {
return errors.New("communications manager already started")
if !atomic.CompareAndSwapInt32(&c.started, 0, 1) {
return fmt.Errorf("communications manager %w", subsystem.ErrSubSystemAlreadyStarted)
}
defer func() {
@@ -56,13 +57,11 @@ func (c *commsManager) GetStatus() (map[string]base.CommsStatus, error) {
func (c *commsManager) Stop() error {
if atomic.LoadInt32(&c.started) == 0 {
return errors.New("communications manager not started")
return fmt.Errorf("communications manager %w", subsystem.ErrSubSystemNotStarted)
}
if atomic.AddInt32(&c.stopped, 1) != 1 {
return errors.New("communications manager is already stopped")
}
defer func() {
atomic.CompareAndSwapInt32(&c.started, 1, 0)
}()
close(c.shutdown)
log.Debugln(log.CommunicationMgr, "Communications manager shutting down...")
return nil
@@ -82,8 +81,6 @@ func (c *commsManager) PushEvent(evt base.Event) {
func (c *commsManager) run() {
defer func() {
// TO-DO shutdown comms connections for connected services (Slack etc)
atomic.CompareAndSwapInt32(&c.stopped, 1, 0)
atomic.CompareAndSwapInt32(&c.started, 1, 0)
log.Debugln(log.CommunicationMgr, "Communications manager shutdown.")
}()