task-processor/internal/app/handler.go

49 lines
707 B
Go
Raw Normal View History

2026-02-18 15:53:29 +03:00
package app
import (
2026-02-18 17:37:37 +03:00
"context"
2026-02-18 15:53:29 +03:00
log "github.com/sirupsen/logrus"
"task-processor/config"
2026-02-18 17:37:37 +03:00
"time"
2026-02-18 15:53:29 +03:00
)
type App struct {
2026-02-18 17:37:37 +03:00
config config.Config
rootCtx context.Context
2026-02-18 15:53:29 +03:00
}
type Deps struct {
2026-02-18 17:37:37 +03:00
Config config.Config
RootCtx context.Context
2026-02-18 15:53:29 +03:00
}
func NewApp(deps Deps) *App {
return &App{
2026-02-18 17:37:37 +03:00
config: deps.Config,
rootCtx: deps.RootCtx,
2026-02-18 15:53:29 +03:00
}
}
2026-02-18 17:37:37 +03:00
func (app *App) Run() error {
2026-02-18 15:53:29 +03:00
log.Info("App started")
2026-02-18 17:37:37 +03:00
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
2026-02-18 15:53:29 +03:00
}