40 lines
870 B
Go
40 lines
870 B
Go
// 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
|
|
}
|
|
}
|