Commit 8d31f7b8 authored by vicotor's avatar vicotor

update server

parent f6e6c29b
......@@ -384,7 +384,7 @@ func (wm *WorkerManager) manageWorker(worker *Worker) error {
}
go wm.doCallback(task.TaskCallback, taskResponse)
_ = wm.AddWorker(worker)
_ = wm.AddWorkerSingle(worker)
wm.Payment(task)
return true
......@@ -475,7 +475,7 @@ func (wm *WorkerManager) handleWorkerMsg(worker *Worker) {
}
worker.deviceInfoHash = infoHash[:]
}
wm.AddWorker(worker)
wm.AddWorkerFirst(worker)
wm.SetWorkerAddr(worker, worker.addr)
}
}
......
......@@ -3,6 +3,7 @@ package server
import (
"context"
"github.com/odysseus/nodemanager/config"
log "github.com/sirupsen/logrus"
"strconv"
)
......@@ -12,7 +13,8 @@ func (wm *WorkerManager) UpdateWorkerDeviceInfo(worker *Worker, deviceInfos stri
}
func (wm *WorkerManager) AddWorker(worker *Worker) error {
func (wm *WorkerManager) AddWorkerFirst(worker *Worker) error {
log.WithField("worker", worker.addr).Info("add worker first time.")
for _, device := range worker.deviceInfo {
// add device to redis
priority := 0
......@@ -28,6 +30,21 @@ func (wm *WorkerManager) AddWorker(worker *Worker) error {
return nil
}
func (wm *WorkerManager) AddWorkerSingle(worker *Worker) error {
log.WithField("worker", worker.addr).Info("add worker on back.")
{
// add device to redis
priority := 0
if err := wm.rdb.LPush(context.Background(), config.WORKER_QUEUE_PREFIX+strconv.Itoa(priority), worker.addr).Err(); err != nil {
}
}
// add worker to redis queue
if err := wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().LocalEndpoint()).Err(); err != nil {
return err
}
return nil
}
func (wm *WorkerManager) ActiveWorker(worker *Worker) {
wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+worker.addr, config.GetConfig().LocalEndpoint())
}
......
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