Last active
October 19, 2020 17:24
-
-
Save weldpua2008/2c2a2b740eaaafe5c8471b58bdb4646e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bytes" | |
"fmt" | |
"github.com/sirupsen/logrus" | |
"github.com/spf13/viper" | |
model "github.com/weldpua2008/supraworker/model" | |
"time" | |
) | |
var ( | |
log = logrus.WithFields(logrus.Fields{"package": "worker"}) | |
) | |
func main() { | |
logrus.SetLevel(logrus.TraceLevel) | |
viper.SetConfigType("yaml") | |
var yamlExample = []byte(` | |
clientId: "j-ClientId" | |
version: "1" | |
`) | |
if err := viper.ReadConfig(bytes.NewBuffer(yamlExample)); err != nil { | |
log.Infof("Can't read config: %v\n", err) | |
} | |
for i := 1116553; i < 10065537; i++ { | |
cmd1 := fmt.Sprintf("/tmp/t.sh %v", i) | |
j := model.NewJob(fmt.Sprintf("JobId-%v", i), cmd1) | |
if err := j.Run(); err != nil { | |
log.Info(fmt.Sprintf("Job %v failed with %s", j.Id, err)) | |
if errFlushBuf := j.FlushSteamsBuffer(); errFlushBuf != nil { | |
log.Infof("Job %v failed to flush buffer due %v", j.Id, errFlushBuf) | |
} | |
log.Infof("j.Failed %v", j.Failed()) | |
} else { | |
dur := time.Since(j.StartAt) | |
log.Debugf("Job %v finished in %v", j.Id, dur) | |
if errFlushBuf := j.FlushSteamsBuffer(); errFlushBuf != nil { | |
log.Tracef("Job %v failed to flush buffer due %v", j.Id, errFlushBuf) | |
} | |
log.Infof("j.Finish %v", j.Finish()) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/tmp/t.sh