task-processor/internal/app/handler.go
2026-02-18 17:37:37 +03:00

48 lines
707 B
Go

package app
import (
"context"
log "github.com/sirupsen/logrus"
"task-processor/config"
"time"
)
type App struct {
config config.Config
rootCtx context.Context
}
type Deps struct {
Config config.Config
RootCtx context.Context
}
func NewApp(deps Deps) *App {
return &App{
config: deps.Config,
rootCtx: deps.RootCtx,
}
}
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
}