Skip to content

Instantly share code, notes, and snippets.

@weldpua2008
Last active October 19, 2020 17:24
Show Gist options
  • Save weldpua2008/2c2a2b740eaaafe5c8471b58bdb4646e to your computer and use it in GitHub Desktop.
Save weldpua2008/2c2a2b740eaaafe5c8471b58bdb4646e to your computer and use it in GitHub Desktop.
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())
}
}
}
@weldpua2008
Copy link
Author

/tmp/t.sh

#!/bin/bash
env LC_CTYPE=C tr -dc '\n a-zA-Z0-9-_$?' < /dev/urandom | head -c $1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment