fix(task/cron): use the correct pointer to build structure
feat(init): included enviroment variable and working directory test(cron): wip
This commit is contained in:
@@ -7,38 +7,37 @@ import (
|
||||
"os/exec"
|
||||
|
||||
"gitea.suyono.dev/suyono/wingmate"
|
||||
"gitea.suyono.dev/suyono/wingmate/cmd/cli"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
// DummyPath = "/workspaces/wingmate/cmd/experiment/dummy/dummy"
|
||||
DummyPath = "/usr/local/bin/wmdummy"
|
||||
EnvDummyPath = "DUMMY_PATH"
|
||||
EnvLog = "LOG"
|
||||
EnvLogMessage = "LOG_MESSAGE"
|
||||
EnvDefaultLogMessage = "oneshot executed"
|
||||
EnvInstanceNum = "INSTANCE_NUM"
|
||||
EnvDefaultInstances = -1
|
||||
EnvDefaultInstances = 0
|
||||
)
|
||||
|
||||
func main() {
|
||||
viper.SetEnvPrefix(wingmate.EnvPrefix)
|
||||
viper.BindEnv(EnvDummyPath)
|
||||
viper.BindEnv(EnvLog)
|
||||
viper.BindEnv(EnvLogMessage)
|
||||
viper.BindEnv(EnvInstanceNum)
|
||||
viper.SetDefault(EnvDummyPath, DummyPath)
|
||||
viper.SetDefault(EnvLogMessage, EnvDefaultLogMessage)
|
||||
viper.SetDefault(EnvInstanceNum, EnvDefaultInstances)
|
||||
|
||||
exePath := viper.GetString(EnvDummyPath)
|
||||
_, childArgs, err := cli.SplitArgs(os.Args)
|
||||
if err != nil {
|
||||
log.Printf("splitargs: %+v", err)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
logPath := viper.GetString(EnvLog)
|
||||
logMessage := viper.GetString(EnvLogMessage)
|
||||
log.Println("log path:", logPath)
|
||||
if logPath != "" {
|
||||
var (
|
||||
err error
|
||||
file *os.File
|
||||
)
|
||||
|
||||
@@ -53,10 +52,12 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
StartInstances(exePath)
|
||||
if len(childArgs) > 0 {
|
||||
StartInstances(childArgs[0], childArgs[1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func StartInstances(exePath string) {
|
||||
func StartInstances(exePath string, args ...string) {
|
||||
num := (rand.Uint32() % 16) + 16
|
||||
|
||||
iNum := viper.GetInt(EnvInstanceNum)
|
||||
@@ -70,7 +71,7 @@ func StartInstances(exePath string) {
|
||||
err error
|
||||
)
|
||||
for ctr = 0; ctr < num; ctr++ {
|
||||
cmd = exec.Command(exePath)
|
||||
cmd = exec.Command(exePath, args...)
|
||||
if err = cmd.Start(); err != nil {
|
||||
log.Printf("failed to run %s: %+v\n", exePath, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user