Skip to content

Commit

Permalink
add configurable browser timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
tedpearson committed Oct 11, 2022
1 parent 7998642 commit a88f435
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/app/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import (
)

func DownloadCsv(config *Config, startDate string, endDate string) (string, error) {
timeout, err := time.ParseDuration(config.Timeout)
if err != nil {
return "", err
}
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithLogf(log.Printf))
defer cancel()
ctx, cancel = context.WithTimeout(ctx, 30*time.Second)
ctx, cancel = context.WithTimeout(ctx, timeout)
defer cancel()

done := make(chan string, 1)
Expand All @@ -29,7 +33,7 @@ func DownloadCsv(config *Config, startDate string, endDate string) (string, erro
}
})

err := chromedp.Run(ctx,
err = chromedp.Run(ctx,
chromedp.Navigate(config.LoginUrl),
chromedp.SetValue("#LoginUsernameTextBox", config.Username, chromedp.NodeVisible),
chromedp.SetValue("#LoginPasswordTextBox", config.Password),
Expand Down
1 change: 1 addition & 0 deletions internal/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Config struct {
LoginUrl string
DownloadDir string
ExtractDays int
Timeout string
InfluxDB InfluxDB
}

Expand Down

0 comments on commit a88f435

Please sign in to comment.