This commit is contained in:
parent
7c45234c95
commit
270cc77d31
4 changed files with 104 additions and 4 deletions
|
|
@ -3,17 +3,20 @@ package app
|
|||
import (
|
||||
"context"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net"
|
||||
"scrapper-mandarake/config"
|
||||
"scrapper-mandarake/internal/scrapper"
|
||||
"scrapper-mandarake/internal/tasks"
|
||||
"scrapper-mandarake/pkg/router"
|
||||
"time"
|
||||
)
|
||||
|
||||
const AppName string = "Mandarake parser"
|
||||
|
||||
type App struct {
|
||||
transport tasks.TaskTransport
|
||||
scrapper scrapper.PriceScrapper
|
||||
transport tasks.TaskTransport
|
||||
scrapper scrapper.PriceScrapper
|
||||
metricsSrv *router.Handler
|
||||
}
|
||||
|
||||
func NewApp(cfg *config.Config) *App {
|
||||
|
|
@ -37,6 +40,11 @@ func NewApp(cfg *config.Config) *App {
|
|||
TaskTimeout: cfg.App.TaskTimeoutSeconds,
|
||||
})
|
||||
|
||||
a.metricsSrv = router.NewHandler(router.Deps{
|
||||
Addr: net.JoinHostPort(cfg.Metrics.Host, cfg.Metrics.Port),
|
||||
GinMode: cfg.Metrics.GinMode,
|
||||
})
|
||||
|
||||
log.Infof("%v: %v", AppName, cfg.App.Mode)
|
||||
return &a
|
||||
}
|
||||
|
|
@ -52,6 +60,13 @@ func (app *App) Run(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
//start metrics server
|
||||
go func() {
|
||||
if err := app.metricsSrv.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
<-ctx.Done()
|
||||
return app.Shutdown(ctx)
|
||||
}
|
||||
|
|
@ -63,6 +78,10 @@ func (app *App) Shutdown(ctx context.Context) error {
|
|||
|
||||
app.scrapper.Stop()
|
||||
|
||||
if err := app.metricsSrv.Shutdown(ctx); err != nil {
|
||||
log.WithError(err).Error("Failed to shutdown server")
|
||||
}
|
||||
|
||||
_ = ctx
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue