Commit 0a0dbbda authored by duanjinfei's avatar duanjinfei

update task handler

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