job.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright 2017 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package storage
  5. import (
  6. "fmt"
  7. "time"
  8. "github.com/miniflux/miniflux/helper"
  9. "github.com/miniflux/miniflux/model"
  10. )
  11. const maxParsingError = 3
  12. // NewBatch returns a serie of jobs.
  13. func (s *Storage) NewBatch(batchSize int) (jobs model.JobList, err error) {
  14. defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:GetJobs] batchSize=%d", batchSize))
  15. query := `
  16. SELECT
  17. id, user_id
  18. FROM feeds
  19. WHERE parsing_error_count < $1
  20. ORDER BY checked_at ASC LIMIT %d`
  21. rows, err := s.db.Query(fmt.Sprintf(query, batchSize), maxParsingError)
  22. if err != nil {
  23. return nil, fmt.Errorf("unable to fetch batch of jobs: %v", err)
  24. }
  25. defer rows.Close()
  26. for rows.Next() {
  27. var job model.Job
  28. if err := rows.Scan(&job.FeedID, &job.UserID); err != nil {
  29. return nil, fmt.Errorf("unable to fetch job: %v", err)
  30. }
  31. jobs = append(jobs, job)
  32. }
  33. return jobs, nil
  34. }