Skip to content

Commit d9e8a68

Browse files
authored
Add elapsed time logging (#62)
1 parent 83f3161 commit d9e8a68

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

scraper/scraper.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func InitScraper() {
4545

4646
scraper.OnRequest(func(r *colly.Request) {
4747
query := r.URL.Query()
48-
for _, key := range []string{"taskHash", "taskType", "taskRegion", "taskRetries", "taskClient"} {
48+
for _, key := range []string{"taskHash", "taskType", "taskRegion", "taskRetries", "taskClient", "taskAddedAt"} {
4949
r.Ctx.Put(key, query.Get(key))
5050
query.Del(key)
5151
}
@@ -57,7 +57,9 @@ func InitScraper() {
5757
})
5858

5959
scraper.OnResponse(func(r *colly.Response) {
60-
logger.Info(fmt.Sprintf("Loaded %v", r.Request.URL))
60+
parsedStartTime, _ := time.Parse(time.RFC3339, r.Request.Ctx.Get("taskAddedAt"))
61+
elapsed := time.Since(parsedStartTime)
62+
logger.Info(fmt.Sprintf("Loaded %v in %v", r.Request.URL, elapsed))
6163
})
6264

6365
scraper.OnHTML("body", func(body *colly.HTMLElement) {

scraper/taskQueue.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
type Task struct {
10+
AddedAt time.Time
1011
ClientIP string
1112
Hash string
1213
URL string
@@ -36,8 +37,9 @@ func NewTaskQueue(bufferSize int) *TaskQueue {
3637

3738
func (q *TaskQueue) AddTask(clientIP, hash, url string) (added bool) {
3839
fullURL := utils.BuildRequest(url, map[string]string{
39-
"taskClient": clientIP,
40-
"taskHash": hash,
40+
"taskAddedAt": time.Now().Format(time.RFC3339),
41+
"taskClient": clientIP,
42+
"taskHash": hash,
4143
})
4244

4345
q.mutex.Lock()

0 commit comments

Comments
 (0)