first commit
This commit is contained in:
39
src/cmd/base.go
Normal file
39
src/cmd/base.go
Normal file
@ -0,0 +1,39 @@
|
||||
// Package cmd defines all runners
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"quantex.com/qfixpt/src/app"
|
||||
"quantex.com/qfixpt/src/client/config"
|
||||
"quantex.com/qfixpt/src/common/tracerr"
|
||||
)
|
||||
|
||||
func NewRunner(fn func(app.Config) error) func(globalCfg, serviceCfg string) error {
|
||||
return func(globalCfg, serviceCfg string) error {
|
||||
cfg, err := config.Read([]string{globalCfg, serviceCfg})
|
||||
if err != nil {
|
||||
return tracerr.Errorf("unable to read config running asyncRun: %s", err.Error())
|
||||
}
|
||||
|
||||
err = fn(cfg)
|
||||
if err != nil {
|
||||
return tracerr.Errorf("error running traderRunner: %s", err.Error())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WaitForInterruptSignal(stopChan chan struct{}) {
|
||||
interrupt := make(chan os.Signal, 10)
|
||||
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
|
||||
select {
|
||||
case <-interrupt:
|
||||
return
|
||||
case <-stopChan:
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user