Commit b5edf8ad authored by vicotor's avatar vicotor

update for worker info

parent 177c8467
......@@ -19,6 +19,7 @@ import (
func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.WorkerInfo) error {
// 2. update worker running info.
wm.workerRunningOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String())
runningList := make([]*operator.WorkerRunningInfo, 0)
for _, running := range worker.info.Models.RunningModels {
id, _ := strconv.Atoi(running.ModelId)
iInfo := &operator.WorkerRunningInfo{
......@@ -26,17 +27,24 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker
ModelId: id,
ExecTime: int(running.ExecTime),
}
_, err := wm.workerRunningOperator.Insert(context.Background(), iInfo)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"model": id,
}).WithError(err).Error("insert worker running model info failed")
continue
}
runningList = append(runningList, iInfo)
}
res, err := wm.workerRunningOperator.InsertMany(context.Background(), runningList)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("insert worker running model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker running model info success")
}
// 3. update worker installed info.
wm.workerInstalledOperator.DeleteByWorkerId(context.Background(), worker.WorkerAccount().String())
installList := make([]*operator.WorkerInstalledInfo, 0)
for _, installed := range worker.info.Models.InstalledModels {
id, _ := strconv.Atoi(installed.ModelId)
iInfo := &operator.WorkerInstalledInfo{
......@@ -46,22 +54,29 @@ func (wm *WorkerManager) updateWorkerInfo(worker *Worker, winfo *operator.Worker
if len(worker.info.Hardware.GPU) > 0 {
iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree
}
_, err := wm.workerInstalledOperator.Insert(context.Background(), iInfo)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"model": id,
}).WithError(err).Error("insert worker installed model info failed")
continue
}
installList = append(installList, iInfo)
}
res, err = wm.workerInstalledOperator.InsertMany(context.Background(), installList)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("insert worker installed model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker installed model info success")
}
// 1. update worker info.
winfo.Hardware = types.PbToHardwareInfo(worker.info.Hardware)
winfo.Models = types.PbToModelInfo(worker.info.Models)
winfo.NodeInfo = types.PbToNodeInfo(worker.info.Info)
err := wm.workerInfoOperator.UpdateWorker(context.Background(), winfo)
err = wm.workerInfoOperator.UpdateWorker(context.Background(), winfo)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("update worker info failed")
return err
}
......@@ -81,7 +96,7 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
}
// 2. add worker running info.
runningList := make([]*operator.WorkerRunningInfo, 0)
for _, running := range worker.info.Models.RunningModels {
id, _ := strconv.Atoi(running.ModelId)
iInfo := &operator.WorkerRunningInfo{
......@@ -89,17 +104,23 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
ModelId: id,
ExecTime: int(running.ExecTime),
}
_, err := wm.workerRunningOperator.Insert(context.Background(), iInfo)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"model": id,
}).WithError(err).Error("insert worker running model info failed")
continue
}
runningList = append(runningList, iInfo)
}
res, err := wm.workerRunningOperator.InsertMany(context.Background(), runningList)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("insert worker running model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker running model info success")
}
// 3. add worker installed info.
installList := make([]*operator.WorkerInstalledInfo, 0)
for _, installed := range worker.info.Models.InstalledModels {
id, _ := strconv.Atoi(installed.ModelId)
iInfo := &operator.WorkerInstalledInfo{
......@@ -109,14 +130,19 @@ func (wm *WorkerManager) addWorkerInfo(worker *Worker) error {
if len(worker.info.Hardware.GPU) > 0 {
iInfo.GpuFree = worker.info.Hardware.GPU[0].MemFree
}
_, err := wm.workerInstalledOperator.Insert(context.Background(), iInfo)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"model": id,
}).WithError(err).Error("insert worker installed model info failed")
continue
}
installList = append(installList, iInfo)
}
res, err = wm.workerInstalledOperator.InsertMany(context.Background(), installList)
if err != nil {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
}).WithError(err).Error("insert worker installed model info failed")
} else {
log.WithFields(log.Fields{
"worker": worker.WorkerAccount().String(),
"count": len(res.InsertedIDs),
}).Debug("insert worker installed model info success")
}
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