Compare commits
No commits in common. "1e331cada590fea93f47e1fb1d13852478a902ac" and "a32b1ef69ba2a67b5f0d0b0448b7594e68d1d1d7" have entirely different histories.
1e331cada5
...
a32b1ef69b
2 changed files with 9 additions and 35 deletions
|
|
@ -10,39 +10,8 @@ import (
|
||||||
"task-processor/internal/shared"
|
"task-processor/internal/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Parser) setupBrowser(ctx context.Context) (string, error) {
|
|
||||||
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
|
||||||
defer allocCancel()
|
|
||||||
|
|
||||||
pageCtx, pageCancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(func(string, ...any) {}))
|
|
||||||
defer pageCancel()
|
|
||||||
|
|
||||||
copyright := "No copyright div found."
|
|
||||||
|
|
||||||
if err := chromedp.Run(pageCtx,
|
|
||||||
chromedp.Navigate("https://www.mandarake.co.jp/"),
|
|
||||||
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
||||||
chromedp.Text(`div.copyright`, ©right, chromedp.ByQuery, chromedp.AtLeast(0)),
|
|
||||||
chromedp.Navigate("https://www.mandarake.co.jp/index2.html"),
|
|
||||||
chromedp.WaitReady("body", chromedp.ByQuery),
|
|
||||||
); err != nil {
|
|
||||||
log.WithError(err).Error(logHeader + logGetPrice + "failed to get single price tag")
|
|
||||||
return copyright, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return copyright, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender chan shared.TaskResult, state *appState.State) {
|
func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender chan shared.TaskResult, state *appState.State) {
|
||||||
log.Infof("%v Start handling tasks", logHeader)
|
log.Infof("%v %v handling tasks", logHeader, logWorker)
|
||||||
log.Infof("%v Setting up browser", logHeader)
|
|
||||||
cr, err := s.setupBrowser(ctx)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error(logHeader + logGetPrice + "failed to setup browser")
|
|
||||||
}
|
|
||||||
log.WithField("Copyright message", cr).Infof("%v Finished setting up browser.", logHeader)
|
|
||||||
|
|
||||||
log.Infof("%v %v processing tasks...", logHeader, logWorker)
|
|
||||||
|
|
||||||
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
|
||||||
defer allocCancel()
|
defer allocCancel()
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ type Deps struct {
|
||||||
const pkgLogHeader string = "Router |"
|
const pkgLogHeader string = "Router |"
|
||||||
|
|
||||||
func NewHandler(deps Deps) *Handler {
|
func NewHandler(deps Deps) *Handler {
|
||||||
engine := gin.New()
|
engine := gin.Default()
|
||||||
|
|
||||||
if deps.GinMode == "release" {
|
if deps.GinMode == "release" {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
|
@ -32,12 +32,17 @@ func NewHandler(deps Deps) *Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logGroup := engine.Group("")
|
engine.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{"msg": "v2"}) })
|
||||||
logGroup.GET("/", func(c *gin.Context) { c.JSON(200, gin.H{"msg": "v2"}) })
|
|
||||||
|
|
||||||
p := ginprometheus.NewPrometheus("gin")
|
p := ginprometheus.NewPrometheus("gin")
|
||||||
p.Use(engine)
|
p.Use(engine)
|
||||||
|
|
||||||
|
engine.Use(gin.LoggerWithConfig(gin.LoggerConfig{
|
||||||
|
Skip: func(c *gin.Context) bool {
|
||||||
|
return c.Request.URL.Path == "/metrics"
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
srv := http.Server{
|
srv := http.Server{
|
||||||
Addr: deps.Addr,
|
Addr: deps.Addr,
|
||||||
Handler: engine,
|
Handler: engine,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue