Skip to content

Commit

Permalink
linting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gosom committed Sep 2, 2023
1 parent b9b5321 commit e3ac237
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- dupl
- errcheck
Expand Down
9 changes: 9 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type IJob interface {
fmt.Stringer
// GetID returns the unique identifier of the job.
GetID() string
// GetParentID returns the parent id of the job
GetParentID() string
// GetMethod returns the http method to use
GetMethod() string
// GetBody returns the body of the request
Expand Down Expand Up @@ -61,6 +63,8 @@ type IJob interface {
type Job struct {
// ID is an identifier for the job
ID string
// ParentID is the parent id of the job
ParentID string
// Method can be one valid HTTP method
Method string
// Body is the request's body
Expand Down Expand Up @@ -209,6 +213,11 @@ func (j *Job) GetID() string {
return j.ID
}

// GetParentID returns the parent id of the job
func (j *Job) GetParentID() string {
return j.ParentID
}

// GetMethod returns the http method to use
func (j *Job) GetMethod() string {
return j.Method
Expand Down
17 changes: 10 additions & 7 deletions scrapemate.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (s *ScrapeMate) DoJob(ctx context.Context, job IJob) (result any, next []IJ
if resp.Error != nil {
err = resp.Error

return
return nil, nil, err
}

if s.cache != nil {
Expand All @@ -372,15 +372,17 @@ func (s *ScrapeMate) DoJob(ctx context.Context, job IJob) (result any, next []IJ
resp.Document, err = s.htmlParser.Parse(ctx, resp.Body)
if err != nil {
s.log.Error("error while setting document", "error", err)
return

return nil, nil, err
}
}

result, next, err = job.Process(ctx, &resp)
if err != nil {
// TODO shall I retry?
s.log.Error("error while processing job", "error", err)
return

return nil, nil, err
}

return result, next, nil
Expand All @@ -407,23 +409,24 @@ func (s *ScrapeMate) doFetch(ctx context.Context, job IJob) (ans Response) {
ok = job.DoCheckResponse(&ans)

if ok {
return
return ans
}

if retryPolicy == DiscardJob {
s.log.Warn("discarding job because of policy")
return

return ans
}

if retryPolicy == StopScraping {
s.log.Warn("stopping scraping because of policy")
s.cancelFn(errors.New("stopping scraping because of policy"))

return
return ans
}

if retry >= maxRetries {
return
return ans
}

retry++
Expand Down

0 comments on commit e3ac237

Please sign in to comment.