Commit 3c0346bc authored by vicotor's avatar vicotor

update worker status

parent 4a779d72
......@@ -3,11 +3,10 @@ package server
import (
"context"
"github.com/odysseus/nodemanager/config"
odysseus "github.com/odysseus/odysseus-protocol/gen/proto/go/base/v1"
"strconv"
)
func (wm *WorkerManager) AddWorker(worker *Worker) {
func (wm *WorkerManager) AddWorker(worker *Worker) error {
for _, device := range worker.deviceInfo {
// add device to redis
priority := 0
......@@ -17,13 +16,19 @@ func (wm *WorkerManager) AddWorker(worker *Worker) {
}
}
// add worker to redis queue
wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusActive, 0)
if err := wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), config.GetConfig().Endpoint).Err(); err != nil {
return err
}
//wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusActive, 0)
return nil
}
func (wm *WorkerManager) ActiveWorker(worker *Worker) {
wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusActive, 0)
wm.rdb.SAdd(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), config.GetConfig().Endpoint)
//wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusActive, 0)
}
func (wm *WorkerManager) InActiveWorker(worker *Worker) {
wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusInActive, 0)
wm.rdb.SRem(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), config.GetConfig().Endpoint)
//wm.rdb.Set(context.Background(), config.WORKER_STATUS_PREFIX+strconv.FormatInt(worker.uuid, 10), odysseus.WorkerStatus_WorkerStatusInActive, 0)
}
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