diff options
author | 2023-11-23 01:24:42 -0800 | |
---|---|---|
committer | 2023-12-01 12:22:30 -0800 | |
commit | 27ec6dbd7d0da7beeda8a5bdd5d114a8beb353b6 (patch) | |
tree | 6fb5fcc89d63cf174edcf2b5a364a7e93de827b6 /internal/model/feed.go | |
parent | a8daee60fb80ec84d1ee8a9f1976689a3012f3c6 (diff) | |
download | v2-27ec6dbd7d0da7beeda8a5bdd5d114a8beb353b6.tar.gz v2-27ec6dbd7d0da7beeda8a5bdd5d114a8beb353b6.tar.zst v2-27ec6dbd7d0da7beeda8a5bdd5d114a8beb353b6.zip |
Setting NextCheckAt due to TTL of a feed in feed.go.
Add unit tests.
Diffstat (limited to 'internal/model/feed.go')
-rw-r--r-- | internal/model/feed.go | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/internal/model/feed.go b/internal/model/feed.go index 987de9df..c9562ac9 100644 --- a/internal/model/feed.go +++ b/internal/model/feed.go @@ -107,21 +107,27 @@ func (f *Feed) CheckedNow() { } // ScheduleNextCheck set "next_check_at" of a feed based on the scheduler selected from the configuration. -func (f *Feed) ScheduleNextCheck(weeklyCount int) { +func (f *Feed) ScheduleNextCheck(weeklyCount int, newTTL int) { + f.TTL = newTTL + // Default to the global config Polling Frequency. + var intervalMinutes int switch config.Opts.PollingScheduler() { case SchedulerEntryFrequency: - var intervalMinutes int - if weeklyCount == 0 { + if weeklyCount <= 0 { intervalMinutes = config.Opts.SchedulerEntryFrequencyMaxInterval() } else { 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()))) } - f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes)) default: - f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(config.Opts.SchedulerRoundRobinMinInterval())) + intervalMinutes = config.Opts.SchedulerRoundRobinMinInterval() } + // If the feed has a TTL defined, we use it to make sure we don't check it too often. + if newTTL > intervalMinutes && newTTL > 0 { + intervalMinutes = newTTL + } + f.NextCheckAt = time.Now().Add(time.Minute * time.Duration(intervalMinutes)) } // FeedCreationRequest represents the request to create a feed. |