diff --git a/server/server.go b/server/server.go index 9773fc5..307b0a4 100644 --- a/server/server.go +++ b/server/server.go @@ -1,14 +1,16 @@ package server import ( + "context" "fmt" "net/http" "git.ostiwe.com/ostiwe-com/status/modules/db" appLog "git.ostiwe.com/ostiwe-com/status/modules/log" - "git.ostiwe.com/ostiwe-com/status/modules/queue" + "git.ostiwe.com/ostiwe-com/status/modules/scheduler" "git.ostiwe.com/ostiwe-com/status/pkg/args" "git.ostiwe.com/ostiwe-com/status/router" + "git.ostiwe.com/ostiwe-com/status/service" "github.com/sirupsen/logrus" ) @@ -21,8 +23,24 @@ func Run(serverArgs *args.ServerCmd) { db.SetGlobal(connect) + scheduler.GlobalAppScheduler, err = scheduler.NewAppScheduler() + if err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create scheduler: %v", err)) + return + } + appLog.Global.Get(appLog.SYSTEM).Info("Start service observer") - go queue.InitQueues() + service.GlobalCheckService = service.NewCheck(scheduler.GlobalAppScheduler) + + if err = service.GlobalCheckService.RegisterTasks(context.Background()); err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed create observe jobs: %v", err)) + return + } + + if err = scheduler.GlobalAppScheduler.StartJobs(); err != nil { + appLog.Global.Get(appLog.SYSTEM).Error(fmt.Sprintf("Startup server error, failed start jobs: %v", err)) + return + } appLog.Global.Put(appLog.SERVER, logrus.New()) appLog.Global.Get(appLog.SERVER).Info("Startup server on port: ", serverArgs.Port)