main
alex 2023-10-17 19:56:27 +02:00
parent 6cb66ad400
commit af58edff0d
5 changed files with 26 additions and 7 deletions

View File

@ -2,6 +2,7 @@ package logger
import (
"fmt"
"jannex/robot-control-manager/modules/utils"
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
"github.com/gofiber/fiber/v2"
@ -13,8 +14,16 @@ func AddSystemLog(format string, v ...any) {
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
}
func AddRexLog(rexId, format string, v ...any) {
func AddRobotLog(robotType uint8, robotId string, format string, v ...any) {
var logType string
if robotType == utils.RobotTypeRex {
logType = "rex"
} else {
logType = "yeet"
}
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
Type: "rex-" + rexId,
Type: logType + "-" + robotId,
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
}

View File

@ -103,6 +103,13 @@ func ProcessJobTask(r *structs.Robot, jobId string, jobName string) {
for r.CurrentJobId != "" && r.CurrentJobId != jobId {
// wait for current job to finish
if r.Status == utils.RobotStatusOffline {
log.Info().Msgf("Robot %s offline. Job with id %s and name %s canceled", r.Name, jobId, jobName)
logger.AddRobotLog(r.Type, r.Id, "Job with id %s and name %s canceled", jobId, jobName)
return
}
fmt.Println("job is processing", r.CurrentJobId, jobId, r.JobsWaitingCount)
time.Sleep(2 * time.Second)
}

View File

@ -2,6 +2,7 @@ package control
import (
"jannex/robot-control-manager/modules/cache"
"jannex/robot-control-manager/modules/logger"
"jannex/robot-control-manager/modules/request"
"jannex/robot-control-manager/modules/robot"
"jannex/robot-control-manager/modules/structs"
@ -60,12 +61,14 @@ func ControlRex(c *fiber.Ctx) error {
}
if r.Status != utils.RobotStatusIdle && r.Status != utils.RobotStatusRunning {
}
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusError})
}
robot.ProcessJobTask(r, body.JobId, body.JobName)
robot.UpdateRobotStatus(r, utils.RobotStatusRunning)
logger.AddRobotLog(utils.RobotTypeRex, r.Id, "Control robot with task: %v", rsutils.MarshalJson(body.Task))
if err := request.Request(fiber.MethodPost, r.Address+":5000/api/v1/control", body.Task); err != nil {
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusError})
}

View File

@ -111,7 +111,7 @@ func FirstRequest(c *fiber.Ctx) error {
addRobotSSEMessage(&newRobot)
logger.AddSystemLog("Robot connected with id %v and type %v", body.Id, utils.GetRobotTypeString(body.Type))
logger.AddRobotLog(newRobot.Type, newRobot.Id, "Robot connected")
}
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusOk})

View File

@ -42,7 +42,7 @@ for i in range(1):
RexRobot("762")
RexRobot("763")
RexRobot("764")
RexRobot("765")
RexRobot("770")
@ -69,4 +69,4 @@ def ping():
return jsonify({'status': 'ok'})
if __name__ == '__main__':
app.run(debug=False, port=5003)
app.run(debug=False, port=5000)