Avoid excessive manual polling with default scheduler
This commit is contained in:
parent
54eb500315
commit
cc44d14722
7 changed files with 40 additions and 15 deletions
|
@ -5,6 +5,7 @@ package api // import "miniflux.app/v2/internal/api"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
json_parser "encoding/json"
|
json_parser "encoding/json"
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -141,9 +142,14 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
slog.Info(
|
||||||
h.pool.Push(jobs)
|
"Triggered a manual refresh of all feeds for a given category from the API",
|
||||||
}()
|
slog.Int64("user_id", userID),
|
||||||
|
slog.Int64("category_id", categoryID),
|
||||||
|
slog.Int("nb_jobs", len(jobs)),
|
||||||
|
)
|
||||||
|
|
||||||
|
go h.pool.Push(jobs)
|
||||||
|
|
||||||
json.NoContent(w, r)
|
json.NoContent(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ package api // import "miniflux.app/v2/internal/api"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
json_parser "encoding/json"
|
json_parser "encoding/json"
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -74,9 +75,13 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
slog.Info(
|
||||||
h.pool.Push(jobs)
|
"Triggered a manual refresh of all feeds from the API",
|
||||||
}()
|
slog.Int64("user_id", userID),
|
||||||
|
slog.Int("nb_jobs", len(jobs)),
|
||||||
|
)
|
||||||
|
|
||||||
|
go h.pool.Push(jobs)
|
||||||
|
|
||||||
json.NoContent(w, r)
|
json.NoContent(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ func (f *Feed) ScheduleNextCheck(weeklyCount int) {
|
||||||
}
|
}
|
||||||
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes))
|
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes))
|
||||||
default:
|
default:
|
||||||
f.NextCheckAt = time.Now()
|
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(config.Opts.PollingFrequency()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,10 @@ func TestFeedScheduleNextCheckDefault(t *testing.T) {
|
||||||
if feed.NextCheckAt.IsZero() {
|
if feed.NextCheckAt.IsZero() {
|
||||||
t.Error(`The next_check_at must be set`)
|
t.Error(`The next_check_at must be set`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if feed.NextCheckAt.After(time.Now().Add(time.Minute * time.Duration(config.Opts.PollingFrequency()))) {
|
||||||
|
t.Error(`The next_check_at should not be after the now + polling frequency`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFeedScheduleNextCheckEntryCountBasedMaxInterval(t *testing.T) {
|
func TestFeedScheduleNextCheckEntryCountBasedMaxInterval(t *testing.T) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList,
|
||||||
FROM
|
FROM
|
||||||
feeds
|
feeds
|
||||||
WHERE
|
WHERE
|
||||||
user_id=$1 AND disabled is false
|
user_id=$1 AND disabled is false AND next_check_at < now()
|
||||||
ORDER BY next_check_at ASC LIMIT %d
|
ORDER BY next_check_at ASC LIMIT %d
|
||||||
`
|
`
|
||||||
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
|
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
|
||||||
|
@ -55,7 +55,7 @@ func (s *Storage) NewCategoryBatch(userID int64, categoryID int64, batchSize int
|
||||||
FROM
|
FROM
|
||||||
feeds
|
feeds
|
||||||
WHERE
|
WHERE
|
||||||
user_id=$1 AND category_id=$2 AND disabled is false
|
user_id=$1 AND category_id=$2 AND disabled is false AND next_check_at < now()
|
||||||
ORDER BY next_check_at ASC LIMIT %d
|
ORDER BY next_check_at ASC LIMIT %d
|
||||||
`
|
`
|
||||||
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID, categoryID)
|
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID, categoryID)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
package ui // import "miniflux.app/v2/internal/ui"
|
package ui // import "miniflux.app/v2/internal/ui"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"miniflux.app/v2/internal/http/request"
|
"miniflux.app/v2/internal/http/request"
|
||||||
|
@ -31,9 +32,14 @@ func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
slog.Info(
|
||||||
h.pool.Push(jobs)
|
"Triggered a manual refresh of all feeds for a given category from the web ui",
|
||||||
}()
|
slog.Int64("user_id", userID),
|
||||||
|
slog.Int64("category_id", categoryID),
|
||||||
|
slog.Int("nb_jobs", len(jobs)),
|
||||||
|
)
|
||||||
|
|
||||||
|
go h.pool.Push(jobs)
|
||||||
|
|
||||||
return categoryID
|
return categoryID
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,9 +36,13 @@ func (h *handler) refreshAllFeeds(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
slog.Info(
|
||||||
h.pool.Push(jobs)
|
"Triggered a manual refresh of all feeds from the web ui",
|
||||||
}()
|
slog.Int64("user_id", userID),
|
||||||
|
slog.Int("nb_jobs", len(jobs)),
|
||||||
|
)
|
||||||
|
|
||||||
|
go h.pool.Push(jobs)
|
||||||
|
|
||||||
html.Redirect(w, r, route.Path(h.router, "feeds"))
|
html.Redirect(w, r, route.Path(h.router, "feeds"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue