main loop

This commit is contained in:
nquidox 2026-02-18 19:58:32 +03:00
parent f6e99b2b65
commit d4cb519ac6

View file

@ -3,13 +3,16 @@ package app
import ( import (
"context" "context"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net"
"task-processor/config" "task-processor/config"
ta "task-processor/internal/taskAgent"
"time" "time"
) )
type App struct { type App struct {
config config.Config config config.Config
rootCtx context.Context rootCtx context.Context
taskAgent ta.TaskAgent
} }
type Deps struct { type Deps struct {
@ -18,9 +21,17 @@ type Deps struct {
} }
func NewApp(deps Deps) *App { func NewApp(deps Deps) *App {
cfg := deps.Config
taskAgent := ta.NewHandler(ta.Deps{
Addr: net.JoinHostPort(cfg.TasksSource.Host, cfg.TasksSource.Port),
Timeout: cfg.TasksSource.Timeout,
})
return &App{ return &App{
config: deps.Config, config: cfg,
rootCtx: deps.RootCtx, rootCtx: deps.RootCtx,
taskAgent: taskAgent,
} }
} }
@ -29,6 +40,21 @@ func (app *App) Run() error {
errChan := make(chan error, 3) errChan := make(chan error, 3)
mainLoop := time.NewTicker(app.config.App.CheckPeriod)
defer mainLoop.Stop()
go func() {
if err := app.processTasks(); err != nil {
errChan <- err
}
for range mainLoop.C {
if err := app.processTasks(); err != nil {
errChan <- err
}
}
}()
select { select {
case <-app.rootCtx.Done(): case <-app.rootCtx.Done():
return app.Shutdown() return app.Shutdown()
@ -46,3 +72,8 @@ func (app *App) Shutdown() error {
_ = ctx _ = ctx
return nil return nil
} }
func (app *App) processTasks() error {
log.Info("Processing tasks")
return nil
}