diff --git a/internal/app/handler.go b/internal/app/handler.go index b2ced79..5f6cca2 100644 --- a/internal/app/handler.go +++ b/internal/app/handler.go @@ -1,24 +1,48 @@ package app import ( + "context" log "github.com/sirupsen/logrus" "task-processor/config" + "time" ) type App struct { - config config.Config + config config.Config + rootCtx context.Context } type Deps struct { - Config config.Config + Config config.Config + RootCtx context.Context } func NewApp(deps Deps) *App { return &App{ - config: deps.Config, + config: deps.Config, + rootCtx: deps.RootCtx, } } -func (app *App) Run() { +func (app *App) Run() error { log.Info("App started") + + errChan := make(chan error, 3) + + select { + case <-app.rootCtx.Done(): + return app.Shutdown() + + case err := <-errChan: + return err + } +} + +func (app *App) Shutdown() error { + log.Info("App shutting down") + ctx, cancel := context.WithTimeout(app.rootCtx, time.Second*10) + defer cancel() + + _ = ctx + return nil }