mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-25 07:26:48 +00:00
exchanges: Initial context propagation (#744)
* gct: phase one context awareness pass * exchanges: context propagation pass * common/requester: force context requirement * gctcli/exchanges: linter fix * rpcserver: fix test using dummy rpc server * backtester: fix comments * grpc: add correct cancel and timeout for commands * rpcserver_test: add comment on dummy server * common: deprecated SendHTTPGetRequest * linter: fix * linter: turn on no context check * apichecker: fix context linter issue * binance: use param context * common: remove checks as this gets executed before main * common: change mutex to RW as clients can be used by multiple go routines. * common: remove init and JIT default client. Unexport global variables and add protection. * common: Add comments * bithumb: after dinner mints fix
This commit is contained in:
@@ -41,7 +41,7 @@ func (g *GctScriptManager) Validate(file string) (err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return tempVM.Run()
|
||||
return tempVM.RunCtx()
|
||||
}
|
||||
|
||||
// ShutdownAll shutdown all
|
||||
|
||||
@@ -109,38 +109,19 @@ func (vm *VM) Compile() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Run runs byte code
|
||||
func (vm *VM) Run() (err error) {
|
||||
if vm.config.Verbose {
|
||||
log.Debugf(log.GCTScriptMgr, "Running script: %s ID: %v", vm.ShortName(), vm.ID)
|
||||
}
|
||||
|
||||
err = vm.Compiled.Run()
|
||||
if err != nil {
|
||||
vm.event(StatusFailure, TypeExecute)
|
||||
return Error{
|
||||
Action: "Run",
|
||||
Cause: err,
|
||||
}
|
||||
}
|
||||
vm.event(StatusSuccess, TypeExecute)
|
||||
return
|
||||
}
|
||||
|
||||
// RunCtx runs compiled byte code with context.Context support.
|
||||
func (vm *VM) RunCtx() (err error) {
|
||||
if vm.ctx == nil {
|
||||
vm.ctx = context.Background()
|
||||
}
|
||||
|
||||
ct, cancel := context.WithTimeout(vm.ctx, vm.config.ScriptTimeout)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), vm.config.ScriptTimeout)
|
||||
defer cancel()
|
||||
|
||||
if vm.config.Verbose {
|
||||
log.Debugf(log.GCTScriptMgr, "Running script: %s ID: %v", vm.ShortName(), vm.ID)
|
||||
log.Debugf(log.GCTScriptMgr,
|
||||
"Running script: %s ID: %v",
|
||||
vm.ShortName(),
|
||||
vm.ID)
|
||||
}
|
||||
|
||||
err = vm.Compiled.RunContext(ct)
|
||||
err = vm.Compiled.RunContext(ctx)
|
||||
if err != nil {
|
||||
vm.event(StatusFailure, TypeExecute)
|
||||
return Error{
|
||||
|
||||
@@ -219,7 +219,7 @@ func TestVMRun(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = testVM.Run()
|
||||
err = testVM.RunCtx()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -444,7 +444,7 @@ func TestVM_CompileInvalid(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = testVM.Run()
|
||||
err = testVM.RunCtx()
|
||||
if err == nil {
|
||||
t.Fatal("unexpected result broken script compiled successfully ")
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package vm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -54,7 +53,6 @@ type VM struct {
|
||||
Path string
|
||||
Script *tengo.Script
|
||||
Compiled *tengo.Compiled
|
||||
ctx context.Context
|
||||
T time.Duration
|
||||
NextRun time.Time
|
||||
S chan struct{}
|
||||
|
||||
Reference in New Issue
Block a user