Commit de555667 authored by vicotor's avatar vicotor

add post task result

parent 83831395
...@@ -4,6 +4,7 @@ go 1.18 ...@@ -4,6 +4,7 @@ go 1.18
require ( require (
github.com/BurntSushi/toml v1.3.2 github.com/BurntSushi/toml v1.3.2
github.com/astaxie/beego v1.12.3
github.com/ethereum/go-ethereum v1.13.10 github.com/ethereum/go-ethereum v1.13.10
github.com/hashicorp/golang-lru v0.5.4 github.com/hashicorp/golang-lru v0.5.4
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
...@@ -14,6 +15,7 @@ require ( ...@@ -14,6 +15,7 @@ require (
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0 github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.2 github.com/spf13/viper v1.18.2
golang.org/x/crypto v0.17.0
google.golang.org/grpc v1.60.1 google.golang.org/grpc v1.60.1
) )
...@@ -48,7 +50,6 @@ require ( ...@@ -48,7 +50,6 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect
go.uber.org/atomic v1.9.0 // indirect go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect golang.org/x/exp v0.0.0-20231110203233-9a3e6036ecaa // indirect
golang.org/x/net v0.19.0 // indirect golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.15.0 // indirect golang.org/x/sys v0.15.0 // indirect
...@@ -56,6 +57,7 @@ require ( ...@@ -56,6 +57,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20231120223509-83a465c0220f // indirect
google.golang.org/protobuf v1.32.0 // indirect google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
) )
......
This diff is collapsed.
...@@ -3,6 +3,7 @@ package server ...@@ -3,6 +3,7 @@ package server
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/golang/protobuf/proto"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
"github.com/odysseus/nodemanager/utils" "github.com/odysseus/nodemanager/utils"
odysseus "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1" odysseus "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1"
...@@ -263,6 +264,21 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error { ...@@ -263,6 +264,21 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
// remove task from cache. // remove task from cache.
worker.recentTask.Remove(result.TaskId) worker.recentTask.Remove(result.TaskId)
} }
taskResponse := &odysseus.TaskResponse{
TaskId: task.TaskId,
TaskResult: result.TaskResult,
TaskUid: task.TaskUid,
TaskFee: task.TaskFee,
}
d, _ := proto.Marshal(taskResponse)
go func() {
err := utils.Post(task.TaskCallback, d)
if err != nil {
log.WithError(err).Error("post task result failed")
} else {
log.WithField("taskid", task.TaskId).Debug("post task result")
}
}()
_ = wm.AddWorker(worker) _ = wm.AddWorker(worker)
// todo: post event for task succeed or failed // todo: post event for task succeed or failed
return true return true
......
package utils
import (
"github.com/astaxie/beego/httplib"
)
func Post(url string, data []byte) error {
_, err := httplib.Post(url).Body(data).Response()
if err != nil {
return err
}
return nil
}
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