aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorGravatar Dror Levin <dror@psybear.com> 2023-08-24 12:02:46 +0200
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-08-31 20:27:09 -0700
commitbea9017b4833ee8608657feb31d650fe48183c8d (patch)
tree88ac5340ed864150b63a2082fad03c034f9e2d1d /internal
parent64c4c6b34743761d0f6ea02fc4d37594781afbf4 (diff)
downloadv2-bea9017b4833ee8608657feb31d650fe48183c8d.tar.gz
v2-bea9017b4833ee8608657feb31d650fe48183c8d.tar.zst
v2-bea9017b4833ee8608657feb31d650fe48183c8d.zip
Add factor for entry_frequency scheduler
Allow the user to increase the frequency of the entry_frequency scheduler by a configurable factor in order to shorten the time between updates.
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config_test.go35
-rw-r--r--internal/config/options.go9
-rw-r--r--internal/config/parser.go2
-rw-r--r--internal/model/feed.go6
-rw-r--r--internal/model/feed_test.go25
5 files changed, 74 insertions, 3 deletions
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 596d640b..d10c4471 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -724,6 +724,41 @@ func TestDefautSchedulerCountBasedMinInterval(t *testing.T) {
}
}
+func TestDefautSchedulerEntryFrequencyFactorValue(t *testing.T) {
+ os.Clearenv()
+
+ parser := NewParser()
+ opts, err := parser.ParseEnvironmentVariables()
+ if err != nil {
+ t.Fatalf(`Parsing failure: %v`, err)
+ }
+
+ expected := defaultSchedulerEntryFrequencyFactor
+ result := opts.SchedulerEntryFrequencyFactor()
+
+ if result != expected {
+ t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_FACTOR value, got %v instead of %v`, result, expected)
+ }
+}
+
+func TestDefautSchedulerEntryFrequencyFactor(t *testing.T) {
+ os.Clearenv()
+ os.Setenv("SCHEDULER_ENTRY_FREQUENCY_FACTOR", "2")
+
+ parser := NewParser()
+ opts, err := parser.ParseEnvironmentVariables()
+ if err != nil {
+ t.Fatalf(`Parsing failure: %v`, err)
+ }
+
+ expected := 2
+ result := opts.SchedulerEntryFrequencyFactor()
+
+ if result != expected {
+ t.Fatalf(`Unexpected SCHEDULER_ENTRY_FREQUENCY_FACTOR value, got %v instead of %v`, result, expected)
+ }
+}
+
func TestPollingParsingErrorLimit(t *testing.T) {
os.Clearenv()
os.Setenv("POLLING_PARSING_ERROR_LIMIT", "100")
diff --git a/internal/config/options.go b/internal/config/options.go
index 5ca6306c..d4a56d4b 100644
--- a/internal/config/options.go
+++ b/internal/config/options.go
@@ -30,6 +30,7 @@ const (
defaultPollingScheduler = "round_robin"
defaultSchedulerEntryFrequencyMinInterval = 5
defaultSchedulerEntryFrequencyMaxInterval = 24 * 60
+ defaultSchedulerEntryFrequencyFactor = 1
defaultPollingParsingErrorLimit = 3
defaultRunMigrations = false
defaultDatabaseURL = "user=postgres password=postgres dbname=miniflux2 sslmode=disable"
@@ -118,6 +119,7 @@ type Options struct {
pollingScheduler string
schedulerEntryFrequencyMinInterval int
schedulerEntryFrequencyMaxInterval int
+ schedulerEntryFrequencyFactor int
pollingParsingErrorLimit int
workerPoolSize int
createAdmin bool
@@ -191,6 +193,7 @@ func NewOptions() *Options {
pollingScheduler: defaultPollingScheduler,
schedulerEntryFrequencyMinInterval: defaultSchedulerEntryFrequencyMinInterval,
schedulerEntryFrequencyMaxInterval: defaultSchedulerEntryFrequencyMaxInterval,
+ schedulerEntryFrequencyFactor: defaultSchedulerEntryFrequencyFactor,
pollingParsingErrorLimit: defaultPollingParsingErrorLimit,
workerPoolSize: defaultWorkerPoolSize,
createAdmin: defaultCreateAdmin,
@@ -368,6 +371,11 @@ func (o *Options) SchedulerEntryFrequencyMinInterval() int {
return o.schedulerEntryFrequencyMinInterval
}
+// SchedulerEntryFrequencyFactor returns the factor for the entry frequency scheduler.
+func (o *Options) SchedulerEntryFrequencyFactor() int {
+ return o.schedulerEntryFrequencyFactor
+}
+
// PollingParsingErrorLimit returns the limit of errors when to stop polling.
func (o *Options) PollingParsingErrorLimit() int {
return o.pollingParsingErrorLimit
@@ -628,6 +636,7 @@ func (o *Options) SortedOptions(redactSecret bool) []*Option {
"RUN_MIGRATIONS": o.runMigrations,
"SCHEDULER_ENTRY_FREQUENCY_MAX_INTERVAL": o.schedulerEntryFrequencyMaxInterval,
"SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL": o.schedulerEntryFrequencyMinInterval,
+ "SCHEDULER_ENTRY_FREQUENCY_FACTOR": o.schedulerEntryFrequencyFactor,
"SCHEDULER_SERVICE": o.schedulerService,
"SERVER_TIMING_HEADER": o.serverTimingHeader,
"WATCHDOG": o.watchdog,
diff --git a/internal/config/parser.go b/internal/config/parser.go
index c754de5c..bb43bafa 100644
--- a/internal/config/parser.go
+++ b/internal/config/parser.go
@@ -135,6 +135,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
p.opts.schedulerEntryFrequencyMaxInterval = parseInt(value, defaultSchedulerEntryFrequencyMaxInterval)
case "SCHEDULER_ENTRY_FREQUENCY_MIN_INTERVAL":
p.opts.schedulerEntryFrequencyMinInterval = parseInt(value, defaultSchedulerEntryFrequencyMinInterval)
+ case "SCHEDULER_ENTRY_FREQUENCY_FACTOR":
+ p.opts.schedulerEntryFrequencyFactor = parseInt(value, defaultSchedulerEntryFrequencyFactor)
case "POLLING_PARSING_ERROR_LIMIT":
p.opts.pollingParsingErrorLimit = parseInt(value, defaultPollingParsingErrorLimit)
// kept for compatibility purpose
diff --git a/internal/model/feed.go b/internal/model/feed.go
index 4add53b6..64269567 100644
--- a/internal/model/feed.go
+++ b/internal/model/feed.go
@@ -115,10 +115,10 @@ func (f *Feed) ScheduleNextCheck(weeklyCount int) {
if weeklyCount == 0 {
intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval()
} else {
- intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount)))
+ intervalMinutes = int(math.Round(float64(7*24*60) / float64(weeklyCount*config.Opts.SchedulerEntryFrequencyFactor())))
+ intervalMinutes = int(math.Min(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMaxInterval())))
+ intervalMinutes = int(math.Max(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMinInterval())))
}
- intervalMinutes = int(math.Min(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMaxInterval())))
- intervalMinutes = int(math.Max(float64(intervalMinutes), float64(config.Opts.SchedulerEntryFrequencyMinInterval())))
f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes))
default:
f.NextCheckAt = time.Now()
diff --git a/internal/model/feed_test.go b/internal/model/feed_test.go
index 91850f50..34f89e90 100644
--- a/internal/model/feed_test.go
+++ b/internal/model/feed_test.go
@@ -152,3 +152,28 @@ func TestFeedScheduleNextCheckEntryCountBasedMinInterval(t *testing.T) {
t.Error(`The next_check_at should not be before the now + min interval`)
}
}
+
+func TestFeedScheduleNextCheckEntryFrequencyFactor(t *testing.T) {
+ factor := 2
+ os.Clearenv()
+ os.Setenv("POLLING_SCHEDULER", "entry_frequency")
+ os.Setenv("SCHEDULER_ENTRY_FREQUENCY_FACTOR", fmt.Sprintf("%d", factor))
+
+ var err error
+ parser := config.NewParser()
+ config.Opts, err = parser.ParseEnvironmentVariables()
+ if err != nil {
+ t.Fatalf(`Parsing failure: %v`, err)
+ }
+ feed := &Feed{}
+ weeklyCount := 7
+ feed.ScheduleNextCheck(weeklyCount)
+
+ if feed.NextCheckAt.IsZero() {
+ t.Error(`The next_check_at must be set`)
+ }
+
+ if feed.NextCheckAt.After(time.Now().Add(time.Minute * time.Duration(config.Opts.SchedulerEntryFrequencyMaxInterval()/factor))) {
+ t.Error(`The next_check_at should not be after the now + factor * count`)
+ }
+}