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 (
"context"
log "github.com/sirupsen/logrus"
"net"
"task-processor/config"
ta "task-processor/internal/taskAgent"
"time"
)
type App struct {
config config.Config
rootCtx context.Context
taskAgent ta.TaskAgent
}
type Deps struct {
@ -18,9 +21,17 @@ type Deps struct {
}
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{
config: deps.Config,
config: cfg,
rootCtx: deps.RootCtx,
taskAgent: taskAgent,
}
}
@ -29,6 +40,21 @@ func (app *App) Run() error {
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 {
case <-app.rootCtx.Done():
return app.Shutdown()
@ -46,3 +72,8 @@ func (app *App) Shutdown() error {
_ = ctx
return nil
}
func (app *App) processTasks() error {
log.Info("Processing tasks")
return nil
}