implemented new version of logger
parent
af58edff0d
commit
aabca4974a
2
go.mod
2
go.mod
|
@ -3,7 +3,7 @@ module jannex/robot-control-manager
|
||||||
go 1.21.0
|
go 1.21.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.ex.umbach.dev/Alex/roese-utils v1.0.14
|
git.ex.umbach.dev/Alex/roese-utils v1.0.16
|
||||||
github.com/gofiber/fiber/v2 v2.49.2
|
github.com/gofiber/fiber/v2 v2.49.2
|
||||||
github.com/google/uuid v1.3.1
|
github.com/google/uuid v1.3.1
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -6,6 +6,10 @@ git.ex.umbach.dev/Alex/roese-utils v1.0.13 h1:zPFUQda4ljskCFdGdV69jjAiblTdIMrubw
|
||||||
git.ex.umbach.dev/Alex/roese-utils v1.0.13/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
git.ex.umbach.dev/Alex/roese-utils v1.0.13/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
||||||
git.ex.umbach.dev/Alex/roese-utils v1.0.14 h1:OdV3RTXOsMZHntUgAl00g+zMux58gUqzRTPw/KNdTAg=
|
git.ex.umbach.dev/Alex/roese-utils v1.0.14 h1:OdV3RTXOsMZHntUgAl00g+zMux58gUqzRTPw/KNdTAg=
|
||||||
git.ex.umbach.dev/Alex/roese-utils v1.0.14/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
git.ex.umbach.dev/Alex/roese-utils v1.0.14/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
||||||
|
git.ex.umbach.dev/Alex/roese-utils v1.0.15 h1:xvqk5yMBkcabjWVymEbmColgSX09IcMQVFz2pKBsDvU=
|
||||||
|
git.ex.umbach.dev/Alex/roese-utils v1.0.15/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
||||||
|
git.ex.umbach.dev/Alex/roese-utils v1.0.16 h1:B9yVx5nL7FfUPJmqHDs58mq8MB2wSox1fK34EP3dqhc=
|
||||||
|
git.ex.umbach.dev/Alex/roese-utils v1.0.16/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI=
|
||||||
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
|
||||||
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
|
2
main.go
2
main.go
|
@ -71,7 +71,7 @@ func main() {
|
||||||
|
|
||||||
router.SetupRoutes(app)
|
router.SetupRoutes(app)
|
||||||
|
|
||||||
rcmlogger.AddSystemLog("Server started")
|
rcmlogger.AddSystemLog(rslogger.LogTypeInfo, "Server started")
|
||||||
|
|
||||||
robot.LoadRobotsFromDatabase()
|
robot.LoadRobotsFromDatabase()
|
||||||
go robot.RobotPingHandler()
|
go robot.RobotPingHandler()
|
||||||
|
|
|
@ -8,22 +8,22 @@ import (
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AddSystemLog(format string, v ...any) {
|
func AddSystemLog(logType string, format string, v ...any) {
|
||||||
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
|
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
|
||||||
Type: "robot-control-manager",
|
Type: "robot-control-manager",
|
||||||
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
|
Logs: []string{logType + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddRobotLog(robotType uint8, robotId string, format string, v ...any) {
|
func AddRobotLog(logType string, robotType uint8, robotId string, format string, v ...any) {
|
||||||
var logType string
|
var lType string
|
||||||
|
|
||||||
if robotType == utils.RobotTypeRex {
|
if robotType == utils.RobotTypeRex {
|
||||||
logType = "rex"
|
lType = "rex"
|
||||||
} else {
|
} else {
|
||||||
logType = "yeet"
|
lType = "yeet"
|
||||||
}
|
}
|
||||||
|
|
||||||
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
|
go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{
|
||||||
Type: logType + "-" + robotId,
|
Type: lType + "-" + robotId,
|
||||||
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
|
Logs: []string{logType + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
"jannex/robot-control-manager/modules/utils"
|
"jannex/robot-control-manager/modules/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
@ -27,18 +28,18 @@ func RobotPingHandler() {
|
||||||
err := request.Request(fiber.MethodGet, robot.Address+":5000/api/v1/ping", nil)
|
err := request.Request(fiber.MethodGet, robot.Address+":5000/api/v1/ping", nil)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.AddSystemLog("Robot ping request failed: %v", err)
|
logger.AddSystemLog(rslogger.LogTypeWarning, "Robot ping request failed: %v", err)
|
||||||
|
|
||||||
if robot.PingRetries == utils.RobotPingRetries {
|
if robot.PingRetries == utils.RobotPingRetries {
|
||||||
UpdateRobotStatus(robot, utils.RobotStatusOffline)
|
UpdateRobotStatus(robot, utils.RobotStatusOffline)
|
||||||
|
|
||||||
logger.AddSystemLog("Robot %s marked as offline because %v attempts have already been made to reach it", robot.Name, utils.RobotPingRetries)
|
logger.AddSystemLog(rslogger.LogTypeWarning, "Robot %s marked as offline because %v attempts have already been made to reach it", robot.Name, utils.RobotPingRetries)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
robot.PingRetries++
|
robot.PingRetries++
|
||||||
|
|
||||||
logger.AddSystemLog("Trying to ping robot %s for %v times failed", robot.Name, robot.PingRetries)
|
logger.AddSystemLog(rslogger.LogTypeWarning, "Trying to ping robot %s for %v times failed", robot.Name, robot.PingRetries)
|
||||||
|
|
||||||
if robot.Status != utils.RobotStatusConnecting {
|
if robot.Status != utils.RobotStatusConnecting {
|
||||||
UpdateRobotStatus(robot, utils.RobotStatusConnecting)
|
UpdateRobotStatus(robot, utils.RobotStatusConnecting)
|
||||||
|
@ -106,7 +107,7 @@ func ProcessJobTask(r *structs.Robot, jobId string, jobName string) {
|
||||||
|
|
||||||
if r.Status == utils.RobotStatusOffline {
|
if r.Status == utils.RobotStatusOffline {
|
||||||
log.Info().Msgf("Robot %s offline. Job with id %s and name %s canceled", r.Name, jobId, jobName)
|
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)
|
logger.AddRobotLog(rslogger.LogTypeWarning, r.Type, r.Id, "Job with id %s and name %s canceled", jobId, jobName)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,5 +242,5 @@ func PermitJoinAutoDisableHandler() {
|
||||||
Body: 0,
|
Body: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.AddSystemLog("Permit join disabled by timer")
|
logger.AddSystemLog(rslogger.LogTypeInfo, "Permit join disabled by timer")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"jannex/robot-control-manager/modules/structs"
|
"jannex/robot-control-manager/modules/structs"
|
||||||
"jannex/robot-control-manager/modules/utils"
|
"jannex/robot-control-manager/modules/utils"
|
||||||
|
|
||||||
|
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||||
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
@ -67,7 +68,7 @@ func ControlRex(c *fiber.Ctx) error {
|
||||||
robot.ProcessJobTask(r, body.JobId, body.JobName)
|
robot.ProcessJobTask(r, body.JobId, body.JobName)
|
||||||
robot.UpdateRobotStatus(r, utils.RobotStatusRunning)
|
robot.UpdateRobotStatus(r, utils.RobotStatusRunning)
|
||||||
|
|
||||||
logger.AddRobotLog(utils.RobotTypeRex, r.Id, "Control robot with task: %v", rsutils.MarshalJson(body.Task))
|
logger.AddRobotLog(rslogger.LogTypeInfo, 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 {
|
if err := request.Request(fiber.MethodPost, r.Address+":5000/api/v1/control", body.Task); err != nil {
|
||||||
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusError})
|
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusError})
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"jannex/robot-control-manager/modules/structs"
|
"jannex/robot-control-manager/modules/structs"
|
||||||
"jannex/robot-control-manager/modules/utils"
|
"jannex/robot-control-manager/modules/utils"
|
||||||
|
|
||||||
|
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||||
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
@ -39,14 +40,14 @@ func SetPermitJoin(c *fiber.Ctx) error {
|
||||||
|
|
||||||
if params.Enabled == 0 {
|
if params.Enabled == 0 {
|
||||||
cache.SetPermitJoin(false)
|
cache.SetPermitJoin(false)
|
||||||
logger.AddSystemLog("Permit join disabled")
|
logger.AddSystemLog(rslogger.LogTypeInfo, "Permit join disabled")
|
||||||
|
|
||||||
if robot.PermitJoinTimer != nil {
|
if robot.PermitJoinTimer != nil {
|
||||||
robot.PermitJoinTimer.Stop()
|
robot.PermitJoinTimer.Stop()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cache.SetPermitJoin(true)
|
cache.SetPermitJoin(true)
|
||||||
logger.AddSystemLog("Permit join enabled")
|
logger.AddSystemLog(rslogger.LogTypeInfo, "Permit join enabled")
|
||||||
|
|
||||||
go robot.PermitJoinAutoDisableHandler()
|
go robot.PermitJoinAutoDisableHandler()
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"jannex/robot-control-manager/modules/utils"
|
"jannex/robot-control-manager/modules/utils"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.ex.umbach.dev/Alex/roese-utils/rslogger"
|
||||||
"git.ex.umbach.dev/Alex/roese-utils/rspagination"
|
"git.ex.umbach.dev/Alex/roese-utils/rspagination"
|
||||||
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
"git.ex.umbach.dev/Alex/roese-utils/rsutils"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
|
@ -111,7 +112,7 @@ func FirstRequest(c *fiber.Ctx) error {
|
||||||
|
|
||||||
addRobotSSEMessage(&newRobot)
|
addRobotSSEMessage(&newRobot)
|
||||||
|
|
||||||
logger.AddRobotLog(newRobot.Type, newRobot.Id, "Robot connected")
|
logger.AddRobotLog(rslogger.LogTypeInfo, newRobot.Type, newRobot.Id, "Robot connected")
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusOk})
|
return c.JSON(structs.StatusResponse{Status: utils.ResponseStatusOk})
|
||||||
|
|
Loading…
Reference in New Issue