mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
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:
@@ -16,7 +16,6 @@ const gctscriptManagerName = "GCTScript"
|
||||
type GctScriptManager struct {
|
||||
config *Config
|
||||
started int32
|
||||
stopped int32
|
||||
shutdown chan struct{}
|
||||
// Optional values to override stored config ('nil' if not overridden)
|
||||
MaxVirtualMachines *uint8
|
||||
@@ -39,10 +38,9 @@ func (g *GctScriptManager) Started() bool {
|
||||
|
||||
// Start starts gctscript subsystem and creates shutdown channel
|
||||
func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error) {
|
||||
if atomic.AddInt32(&g.started, 1) != 1 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStarted)
|
||||
if !atomic.CompareAndSwapInt32(&g.started, 0, 1) {
|
||||
return fmt.Errorf("%s %w", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStarted)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
@@ -59,16 +57,19 @@ func (g *GctScriptManager) Start(wg *sync.WaitGroup) (err error) {
|
||||
// Stop stops gctscript subsystem along with all running Virtual Machines
|
||||
func (g *GctScriptManager) Stop() error {
|
||||
if atomic.LoadInt32(&g.started) == 0 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemNotStarted)
|
||||
}
|
||||
|
||||
if atomic.AddInt32(&g.stopped, 1) != 1 {
|
||||
return fmt.Errorf("%s %s", gctscriptManagerName, subsystem.ErrSubSystemAlreadyStopped)
|
||||
return fmt.Errorf("%s %w", gctscriptManagerName, subsystem.ErrSubSystemNotStarted)
|
||||
}
|
||||
defer func() {
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
}()
|
||||
|
||||
log.Debugln(log.GCTScriptMgr, gctscriptManagerName, subsystem.MsgSubSystemShuttingDown)
|
||||
err := g.ShutdownAll()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
close(g.shutdown)
|
||||
return g.ShutdownAll()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GctScriptManager) run(wg *sync.WaitGroup) {
|
||||
@@ -77,8 +78,6 @@ func (g *GctScriptManager) run(wg *sync.WaitGroup) {
|
||||
SetDefaultScriptOutput()
|
||||
g.autoLoad()
|
||||
defer func() {
|
||||
atomic.CompareAndSwapInt32(&g.stopped, 1, 0)
|
||||
atomic.CompareAndSwapInt32(&g.started, 1, 0)
|
||||
wg.Done()
|
||||
log.Debugln(log.GCTScriptMgr, gctscriptManagerName, subsystem.MsgSubSystemShutdown)
|
||||
}()
|
||||
|
||||
@@ -60,16 +60,16 @@ func TestGctScriptManagerStartStopNominal(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if mgr.started != 1 || mgr.stopped != 0 {
|
||||
t.Errorf("Manager should be started (%v, %v)", mgr.started, mgr.stopped)
|
||||
if mgr.started != 1 {
|
||||
t.Errorf("Manager should be started (%v)", mgr.started)
|
||||
}
|
||||
err = mgr.Stop()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
wg.Wait()
|
||||
if mgr.stopped != 0 {
|
||||
t.Errorf("Manager should be stopped, expected=%v, got %v", 0, mgr.stopped)
|
||||
if mgr.started != 0 {
|
||||
t.Errorf("Manager should be stopped, expected=%v, got %v", 0, mgr.started)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ func TestGctScriptManagerGetMaxVirtualMachines(t *testing.T) {
|
||||
type fields struct {
|
||||
config *Config
|
||||
started int32
|
||||
stopped int32
|
||||
shutdown chan struct{}
|
||||
MaxVirtualMachines *uint8
|
||||
}
|
||||
@@ -113,7 +112,6 @@ func TestGctScriptManagerGetMaxVirtualMachines(t *testing.T) {
|
||||
g := &GctScriptManager{
|
||||
config: tt.fields.config,
|
||||
started: tt.fields.started,
|
||||
stopped: tt.fields.stopped,
|
||||
shutdown: tt.fields.shutdown,
|
||||
MaxVirtualMachines: tt.fields.MaxVirtualMachines,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user