Commit 0a0dbbda authored by duanjinfei's avatar duanjinfei

update task handler

parent 559ca15b
......@@ -10,6 +10,8 @@ const (
ContentType = "type"
RedirectCode = 303
UseFileCache = "USE-FILE-CACHE"
Prefer = "Prefer"
Async = "respond-async"
ModelPublishStatusYes = 1
ModelPublishStatusNo = 2
)
......@@ -30,12 +30,17 @@ type TaskParam struct {
Body []byte `json:"body"`
}
type ContainerRequest struct {
WebHook string `json:"webhook"`
}
type TaskResult struct {
TaskHttpHeaders []byte
TaskExecTime int64
TaskHttpStatusCode int32
TaskRespBody []byte
TaskIsSuccess bool
TaskExecError string
}
type ApiResp struct {
......@@ -72,6 +77,12 @@ type ModelInfo struct {
PublishStatus int `json:"publish_status"`
}
type FileCacheResult struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data string `json:"data"`
}
type ComputeResult struct {
Code string `json:"code"`
Msg string `json:"msg"`
......
......@@ -239,7 +239,8 @@ func SubmitResultResp(params ...interface{}) *nodemanagerV1.WorkerMessage {
TaskId: taskId,
ContainerSignature: containerSign,
MinerSignature: minerSign,
TaskResultCode: taskExecResult.TaskHttpStatusCode,
TaskExecuteCode: taskExecResult.TaskHttpStatusCode,
TaskExecuteError: taskExecResult.TaskExecError,
TaskResultHeader: taskExecResult.TaskHttpHeaders,
TaskExecuteDuration: uint64(taskExecResult.TaskExecTime),
IsSuccessed: isSuccess,
......
......@@ -8,6 +8,7 @@ import (
"example.com/m/operate"
"example.com/m/utils"
"example.com/m/validator"
"fmt"
nodeManagerV1 "github.com/odysseus/odysseus-protocol/gen/proto/go/nodemanager/v1"
"google.golang.org/grpc"
"time"
......@@ -293,6 +294,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
TaskHttpHeaders: nil,
TaskIsSuccess: false,
TaskExecTime: 0,
TaskExecError: "",
}
if taskExecResInterface != nil {
taskExecRes = taskExecResInterface.(*models.TaskResult)
......@@ -302,6 +304,7 @@ func handlerMsg(nodeManager *models.NodeManagerClient,
if containerSign == nil || len(containerSign) == 0 {
log.Error("Container signing failed................")
isSuccess = false
taskExecRes.TaskExecError = fmt.Sprintf("%s,%s", taskExecRes.TaskExecError, "Container sign failed")
}
reqHash, respHash, minerSign := taskMsgWorker.GetMinerSign(taskMsg, taskExecRes.TaskRespBody)
params := buildParams(taskMsg.TaskId, containerSign, minerSign, taskExecRes, isSuccess)
......
This diff is collapsed.
package utils
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/base64"
"encoding/json"
"example.com/m/log"
"example.com/m/models"
"fmt"
......@@ -110,6 +112,7 @@ func IsBase64ImageStr(imageStr string) (bool, []byte, string, string) {
}
decodeBytes, err := base64.StdEncoding.DecodeString(base64Code)
if err != nil {
log.WithError(err).Error("base64 decode string failed")
return false, nil, "", ""
}
formatStr := strings.Split(strings.Split(base64CodePrefix, ";")[0], ":")[1]
......@@ -151,3 +154,16 @@ func MatchContainerQueryString(params map[string]string) string {
}
return values.Encode()
}
func EncodeJsonEscapeHTML(apiRes any) []byte {
apiResBody := bytes.NewBuffer([]byte{})
encoder := json.NewEncoder(apiResBody)
encoder.SetEscapeHTML(false)
err := encoder.Encode(apiRes)
if err != nil {
log.WithError(err).Error("encoder Encode")
return apiResBody.Bytes()
}
log.WithField("apiResBody", string(apiResBody.Bytes())).Info("model resp")
return apiResBody.Bytes()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment