mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-21 23:16:49 +00:00
Engine/GCTScript: Refactor script manager (#580)
* refactor script manager
* remove singleton GCTScriptConfig
* create constant for ".gct" extension
* move GctScriptManager into vm package
* reduce script manager global dependencies
* use manager struct to store runtime override values
* enable/disable scripting subsystem now doesn't store the setting in
config (aligned with other subsystems)
* setting max VMs via start option doesn't change config
* instantiate scriptmanager as part of creating a new Engine
* script manager config is now set during instantiation
* run script manager when enabled in conf or explicitly enabled
* use the Started() method to check if script manager is running
* in tests set script manager as running
* script manager adjustments
* create manager before attempting overrides
* check for nil config when creating script manager
* fix script manager waitgroup counter increased too late
* move autoload() function to autoload.go
* add tests to script manager
This commit is contained in:
@@ -9,16 +9,16 @@ import (
|
||||
)
|
||||
|
||||
// New returns a new instance of VM
|
||||
func New() *VM {
|
||||
if VMSCount.Len() >= int32(GCTScriptConfig.MaxVirtualMachines) {
|
||||
if GCTScriptConfig.Verbose {
|
||||
func (g *GctScriptManager) New() *VM {
|
||||
if VMSCount.Len() >= int32(g.GetMaxVirtualMachines()) {
|
||||
if g.config.Verbose {
|
||||
log.Warnf(log.GCTScriptMgr, "GCTScript MaxVirtualMachines (%v) hit, unable to start further instances",
|
||||
GCTScriptConfig.MaxVirtualMachines)
|
||||
g.GetMaxVirtualMachines())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
VMSCount.add()
|
||||
vm := NewVM()
|
||||
vm := g.NewVM()
|
||||
if vm == nil {
|
||||
VMSCount.remove()
|
||||
} else {
|
||||
@@ -29,10 +29,10 @@ func New() *VM {
|
||||
|
||||
// Validate will attempt to execute a script in a test/non-live environment
|
||||
// to confirm it passes requirements for execution
|
||||
func Validate(file string) (err error) {
|
||||
func (g *GctScriptManager) Validate(file string) (err error) {
|
||||
validator.IsTestExecution.Store(true)
|
||||
defer validator.IsTestExecution.Store(false)
|
||||
tempVM := NewVM()
|
||||
tempVM := g.NewVM()
|
||||
err = tempVM.Load(file)
|
||||
if err != nil {
|
||||
return
|
||||
@@ -45,8 +45,8 @@ func Validate(file string) (err error) {
|
||||
}
|
||||
|
||||
// ShutdownAll shutdown all
|
||||
func ShutdownAll() (err error) {
|
||||
if GCTScriptConfig.Verbose {
|
||||
func (g *GctScriptManager) ShutdownAll() (err error) {
|
||||
if g.config.Verbose {
|
||||
log.Debugln(log.GCTScriptMgr, "Shutting down all Virtual Machines")
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ func ShutdownAll() (err error) {
|
||||
}
|
||||
|
||||
// RemoveVM remove VM from list
|
||||
func RemoveVM(id uuid.UUID) error {
|
||||
func (g *GctScriptManager) RemoveVM(id uuid.UUID) error {
|
||||
if _, f := AllVMSync.Load(id); !f {
|
||||
return fmt.Errorf(ErrNoVMFound, id.String())
|
||||
}
|
||||
|
||||
AllVMSync.Delete(id)
|
||||
VMSCount.remove()
|
||||
if GCTScriptConfig.Verbose {
|
||||
if g.config.Verbose {
|
||||
log.Debugf(log.GCTScriptMgr, "VM %v removed from AllVMs", id)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user