From d4cb519ac655f49c643374baba67a6c644e41ce9 Mon Sep 17 00:00:00 2001 From: nquidox Date: Wed, 18 Feb 2026 19:58:32 +0300 Subject: [PATCH] main loop --- internal/app/handler.go | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/internal/app/handler.go b/internal/app/handler.go index 5f6cca2..ed26e55 100644 --- a/internal/app/handler.go +++ b/internal/app/handler.go @@ -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 + 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, - rootCtx: deps.RootCtx, + 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 +}