本文整理匯總了Golang中github.com/flike/kingtask/task.TaskRequest.Uuid方法的典型用法代碼示例。如果您正苦於以下問題:Golang TaskRequest.Uuid方法的具體用法?Golang TaskRequest.Uuid怎麽用?Golang TaskRequest.Uuid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flike/kingtask/task.TaskRequest
的用法示例。
在下文中一共展示了TaskRequest.Uuid方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: resetTaskRequest
func (b *Broker) resetTaskRequest(args []interface{}) error {
var err error
if len(args) == 0 || len(args) != config.TaskRequestItemCount {
return errors.ErrInvalidArgument
}
request := new(task.TaskRequest)
request.Uuid = args[0].(string)
request.BinName = args[1].(string)
request.Args = args[2].(string)
request.StartTime, err = strconv.ParseInt(args[3].(string), 10, 64)
if err != nil {
return err
}
request.TimeInterval = args[4].(string)
request.Index, err = strconv.Atoi(args[5].(string))
if err != nil {
return err
}
vec := strings.Split(request.TimeInterval, " ")
request.Index++
if request.Index < len(vec) {
timeLater, err := strconv.Atoi(vec[request.Index])
if err != nil {
return err
}
afterTime := time.Second * time.Duration(timeLater)
b.timer.NewTimer(afterTime, b.AddRequestToRedis, request)
} else {
golog.Error("Broker", "HandleFailTask", "retry max time", 0,
"key", fmt.Sprintf("t_%s", request.Uuid))
return errors.ErrTryMaxTimes
}
return nil
}
示例2: CreateRpcTaskRequest
func (b *Broker) CreateRpcTaskRequest(c *echo.Context) error {
args := struct {
Method string `json:"method"`
URL string `json:"url"`
Args string `json:"args"` //json Marshal後的字符串
StartTime int64 `json:"start_time,string"`
TimeInterval string `json:"time_interval"` //空格分隔各個參數
MaxRunTime int64 `json:"max_run_time,string"`
}{}
err := c.Bind(&args)
if err != nil {
return c.JSON(http.StatusForbidden, err.Error())
}
fmt.Println(args)
taskRequest := new(task.TaskRequest)
taskRequest.Uuid = uuid.New()
if len(args.URL) == 0 {
return c.JSON(http.StatusForbidden, errors.ErrInvalidArgument.Error())
}
taskRequest.BinName = args.URL
taskRequest.Args = args.Args
taskRequest.StartTime = args.StartTime
taskRequest.TimeInterval = args.TimeInterval
taskRequest.Index = 0
taskRequest.MaxRunTime = args.MaxRunTime
switch args.Method {
case "GET":
taskRequest.TaskType = task.RpcTaskGET
case "POST":
taskRequest.TaskType = task.RpcTaskPOST
case "PUT":
taskRequest.TaskType = task.RpcTaskPUT
case "DELETE":
taskRequest.TaskType = task.RpcTaskDELETE
default:
return c.JSON(http.StatusForbidden, errors.ErrInvalidArgument.Error())
}
err = b.HandleRequest(taskRequest)
if err != nil {
return c.JSON(http.StatusForbidden, err.Error())
}
golog.Info("Broker", "CreateRpcTaskRequest", "ok", 0,
"uuid", taskRequest.Uuid,
"bin_name", taskRequest.BinName,
"args", taskRequest.Args,
"start_time", taskRequest.StartTime,
"time_interval", taskRequest.TimeInterval,
"index", taskRequest.Index,
"max_run_time", taskRequest.MaxRunTime,
"task_type", taskRequest.TaskType,
)
return c.JSON(http.StatusOK, taskRequest.Uuid)
}
示例3: DoTaskRequest
func (w *Worker) DoTaskRequest(args []interface{}) (*task.TaskResult, error) {
var err error
var output string
req := new(task.TaskRequest)
ret := new(task.TaskResult)
req.Uuid = args[0].(string)
req.BinName = args[1].(string)
req.Args = args[2].(string)
req.StartTime, err = strconv.ParseInt(args[3].(string), 10, 64)
if err != nil {
return nil, err
}
req.TimeInterval = args[4].(string)
req.Index, err = strconv.Atoi(args[5].(string))
if err != nil {
return nil, err
}
req.MaxRunTime, err = strconv.ParseInt(args[6].(string), 10, 64)
if err != nil {
return nil, err
}
req.TaskType, err = strconv.Atoi(args[7].(string))
if err != nil {
return nil, err
}
switch req.TaskType {
case task.ScriptTask:
output, err = w.DoScriptTaskRequest(req)
case task.RpcTaskGET, task.RpcTaskPOST, task.RpcTaskPUT, task.RpcTaskDELETE:
output, err = w.DoRpcTaskRequest(req)
default:
err = errors.ErrInvalidArgument
golog.Error("Worker", "DoTaskRequest", "task type error", 0, "task_type", req.TaskType)
}
ret.TaskRequest = *req
//執行任務失敗,
if err != nil {
ret.IsSuccess = int64(0)
ret.Result = err.Error()
return ret, nil
}
ret.IsSuccess = int64(1)
ret.Result = output
return ret, nil
}
示例4: DoTaskRequest
func (w *Worker) DoTaskRequest(args []interface{}) (*task.TaskResult, error) {
var err error
var output string
req := new(task.TaskRequest)
ret := new(task.TaskResult)
req.Uuid = args[0].(string)
req.BinName = args[1].(string)
req.Args = args[2].(string)
req.StartTime, err = strconv.ParseInt(args[3].(string), 10, 64)
if err != nil {
return nil, err
}
req.TimeInterval = args[4].(string)
req.Index, err = strconv.Atoi(args[5].(string))
if err != nil {
return nil, err
}
binPath := path.Clean(w.cfg.BinPath + "/" + req.BinName)
_, err = os.Stat(binPath)
if err != nil && os.IsNotExist(err) {
golog.Error("worker", "DoTaskRequest", "File not exist", 0,
"key", fmt.Sprintf("t_%s", req.Uuid),
"bin_path", binPath,
)
return nil, errors.ErrFileNotExist
}
if len(req.Args) == 0 {
output, err = w.ExecBin(binPath, nil)
} else {
argsVec := strings.Split(req.Args, " ")
output, err = w.ExecBin(binPath, argsVec)
}
ret.TaskRequest = *req
//執行任務失敗
if err != nil {
ret.IsSuccess = int64(0)
ret.Result = err.Error()
return ret, nil
}
ret.IsSuccess = int64(1)
ret.Result = output
return ret, nil
}
示例5: CreateScriptTaskRequest
func (b *Broker) CreateScriptTaskRequest(c *echo.Context) error {
args := struct {
BinName string `json:"bin_name"`
Args string `json:"args"` //空格分隔各個參數
StartTime int64 `json:"start_time,string"`
TimeInterval string `json:"time_interval"` //空格分隔各個參數
MaxRunTime int64 `json:"max_run_time,string"`
}{}
err := c.Bind(&args)
if err != nil {
return c.JSON(http.StatusForbidden, err.Error())
}
taskRequest := new(task.TaskRequest)
taskRequest.Uuid = uuid.New()
if len(args.BinName) == 0 {
return c.JSON(http.StatusForbidden, errors.ErrInvalidArgument.Error())
}
taskRequest.BinName = args.BinName
taskRequest.Args = args.Args
taskRequest.StartTime = args.StartTime
taskRequest.TimeInterval = args.TimeInterval
taskRequest.Index = 0
taskRequest.MaxRunTime = args.MaxRunTime
taskRequest.TaskType = task.ScriptTask
err = b.HandleRequest(taskRequest)
if err != nil {
return c.JSON(http.StatusForbidden, err.Error())
}
golog.Info("Broker", "CreateScriptTaskRequest", "ok", 0,
"uuid", taskRequest.Uuid,
"bin_name", taskRequest.BinName,
"args", taskRequest.Args,
"start_time", taskRequest.StartTime,
"time_interval", taskRequest.TimeInterval,
"index", taskRequest.Index,
"max_run_time", taskRequest.MaxRunTime,
"task_type", taskRequest.TaskType,
)
return c.JSON(http.StatusOK, taskRequest.Uuid)
}