Make the feed-poll interval site-wide instead of per-feed

Replaces Feed.fetch_interval_minutes with a single admin-editable
SiteSettings.fetch_interval_minutes (apps.core), following the same
singleton-row pattern as accounts.SetupLock. Per-feed error backoff is
unchanged — only the configured baseline interval is now shared across
every feed, loaded once per poll_due_feeds run rather than queried per
feed. EVECTION_MIN_FETCH_INTERVAL_MINUTES keeps working as the floor
underneath it.

SiteSettings is registered in Django admin as a singleton: "Add" is
only offered when no row exists yet, and delete is always refused.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ksmithandClaude Sonnet 5 committed 2026-10-31 12:59:47 -06:00
1 parent a1ea2e5662
commit dc8b9ff83b
11 files changed
+203 -20

No files matched your search

@@ -0,0 +1,17 @@
# Generated by Django 5.2.18 on 2026-10-31 18:56
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("feeds", "0003_feed_claimed_at"),
]
operations = [
migrations.RemoveField(
model_name="feed",
name="fetch_interval_minutes",
),
]
+4 -2
View File
@@ -35,8 +35,10 @@ class Feed(models.Model):
)
last_error_message = models.TextField(blank=True)
# Instance-wide, not a per-user preference — see class docstring.
fetch_interval_minutes = models.PositiveIntegerField(default=60)
# The poll interval itself is site-wide now (apps.core.models.
# SiteSettings), not per-feed — only the error-driven backoff on top
# of it still varies per feed (see apps.feeds.services.fetcher.
# effective_interval_minutes).
fetch_error_count = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)
+9 -6
View File
@@ -124,14 +124,17 @@ def _entry_content_html(entry) -> str:
return getattr(entry, "summary", "") or ""
def effective_interval_minutes(feed: Feed) -> int:
"""The actual polling interval to use, applying exponential backoff on
top of the admin-configured ``fetch_interval_minutes`` for feeds that
are currently erroring. ``fetch_interval_minutes`` itself is never
mutated by the fetcher — it's the admin's chosen baseline.
def effective_interval_minutes(feed: Feed, configured_interval_minutes: int) -> int:
"""The actual polling interval to use for `feed`, applying exponential
backoff on top of the site-wide `configured_interval_minutes` (see
apps.core.models.SiteSettings) for a feed that's currently erroring.
Takes the configured value as a parameter rather than querying
SiteSettings itself, since this runs once per feed (apps.feeds.tasks
calls it from a list comprehension over every active feed) and the
site-wide value doesn't vary by feed.
"""
floor = getattr(settings, "EVECTION_MIN_FETCH_INTERVAL_MINUTES", 15)
base = max(feed.fetch_interval_minutes, floor)
base = max(configured_interval_minutes, floor)
if feed.fetch_error_count <= 0:
return base
backoff = base * (2**feed.fetch_error_count)
+8 -4
View File
@@ -8,6 +8,7 @@ from django.db.models import Q
from django.utils import timezone
from apps.articles.tasks import apply_filter_rules_for_feed
from apps.core.models import SiteSettings
from .models import Feed
from .opml import import_opml
@@ -32,12 +33,15 @@ def poll_due_feeds():
"""
now = timezone.now()
claim_stale_before = now - timedelta(minutes=CLAIM_STALE_MINUTES)
# Loaded once per call, not per feed — the interval is site-wide
# (apps.core.models.SiteSettings), so every feed below shares it.
configured_interval = SiteSettings.load().fetch_interval_minutes
due_feed_ids = [
feed.id
for feed in Feed.objects.filter(is_active=True).only(
"id", "last_fetched_at", "fetch_interval_minutes", "fetch_error_count"
"id", "last_fetched_at", "fetch_error_count"
)
if _is_due(feed)
if _is_due(feed, configured_interval)
]
claimed_ids = []
for feed_id in due_feed_ids:
@@ -57,10 +61,10 @@ def poll_due_feeds():
return len(claimed_ids)
def _is_due(feed: Feed) -> bool:
def _is_due(feed: Feed, configured_interval_minutes: int) -> bool:
if feed.last_fetched_at is None:
return True
interval = effective_interval_minutes(feed)
interval = effective_interval_minutes(feed, configured_interval_minutes)
return feed.last_fetched_at <= timezone.now() - timedelta(minutes=interval)
+1 -1
View File
@@ -136,7 +136,7 @@ def test_unparseable_feed_records_error_and_backs_off(feed):
assert result.status == Feed.STATUS_ERROR
assert feed.fetch_error_count == 1
assert effective_interval_minutes(feed) > feed.fetch_interval_minutes
assert effective_interval_minutes(feed, 60) > 60
@pytest.mark.django_db
-5
View File
@@ -16,17 +16,14 @@ def test_poll_due_feeds_dispatches_only_due_feeds():
recently_fetched = Feed.objects.create(
feed_url="https://b.example.com/feed.xml",
last_fetched_at=timezone.now(),
fetch_interval_minutes=60,
)
overdue = Feed.objects.create(
feed_url="https://c.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
)
inactive_but_overdue = Feed.objects.create(
feed_url="https://d.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
is_active=False,
)
@@ -48,7 +45,6 @@ def test_poll_due_feeds_does_not_reclaim_a_feed_it_just_claimed():
overdue = Feed.objects.create(
feed_url="https://c.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
)
with patch("apps.feeds.tasks.fetch_feed.delay") as mock_delay:
@@ -69,7 +65,6 @@ def test_poll_due_feeds_reclaims_a_stale_claim():
overdue = Feed.objects.create(
feed_url="https://c.example.com/feed.xml",
last_fetched_at=timezone.now() - timedelta(hours=2),
fetch_interval_minutes=60,
claimed_at=timezone.now() - timedelta(minutes=CLAIM_STALE_MINUTES + 1),
)