page timeout added

This commit is contained in:
nquidox 2026-02-28 23:33:22 +03:00
parent 56309cafb9
commit f466566505
3 changed files with 17 additions and 9 deletions

View file

@ -16,9 +16,6 @@ func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender ch
allocCtx, allocCancel := chromedp.NewRemoteAllocator(ctx, s.externalBrowser)
defer allocCancel()
sessionCtx, sessionCancel := chromedp.NewContext(allocCtx /* chromedp.WithLogf(log.Printf) */, chromedp.WithLogf(func(string, ...any) {}))
defer sessionCancel()
receiver := make(chan shared.Task, len(tasks))
for _, task := range tasks {
receiver <- task
@ -31,7 +28,7 @@ func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender ch
wg.Add(1)
go func() {
defer wg.Done()
s.worker(sessionCtx, receiver, sender)
s.worker(allocCtx, receiver, sender)
}()
}
wg.Wait()
@ -42,14 +39,20 @@ func (s *Parser) HandleTasks(ctx context.Context, tasks []shared.Task, sender ch
func (s *Parser) worker(ctx context.Context, receiver chan shared.Task, sender chan shared.TaskResult) {
for task := range receiver {
taskCtx, taskCancel := chromedp.NewContext(ctx /* chromedp.WithLogf(log.Printf) */, chromedp.WithLogf(func(string, ...any) {}))
timeoutCtx, timeoutCancel := context.WithTimeout(taskCtx, s.taskTimeout)
log.WithField("task_uuid", task.MerchUuid).Infof("%v %v processing task", logHeader, logWorker)
//price will be zeroPrice value in case of any error or if price not found
price := s.getMinimalPrice(ctx, task)
price := s.getMinimalPrice(timeoutCtx, task)
sender <- shared.TaskResult{
MerchUuid: task.MerchUuid,
Origin: task.Origin,
Price: price,
}
timeoutCancel()
taskCancel()
}
}