Extend DocumentStore.register_source() to accept scheduling parameters and add a get_sources_due_for_poll() query method needed by the Poller scheduler.
Requirements
- Add
poll_strategy: PollStrategy = PollStrategy.PULL and poll_interval_sec: int | None = None parameters to DocumentStore.register_source()
- The INSERT statement in
register_source() must pass these values into the sources table columns poll_strategy and poll_interval_sec
- The existing
INSERT OR IGNORE idempotency behavior must be preserved
- Add
get_sources_due_for_poll() -> list[dict] method that queries sources where: poll_strategy = 'pull' AND (last_fetched_at IS NULL OR datetime(last_fetched_at, '+' || poll_interval_sec || ' seconds') < datetime('now'))
- Returned dicts must include at minimum:
source_id, adapter_id, poll_interval_sec, last_fetched_at
Design Guidance
File to modify: src/context_library/storage/document_store.py
Current register_source signature (from codebase exploration):
def register_source(self, source_id: str, adapter_id: str, domain: Domain, origin_ref: str) -> None
New signature:
def register_source(
self,
source_id: str,
adapter_id: str,
domain: Domain,
origin_ref: str,
poll_strategy: PollStrategy = PollStrategy.PULL,
poll_interval_sec: int | None = None,
) -> None
The SQLite sources table already has these columns (from the existing schema):
poll_strategy TEXT NOT NULL CHECK (poll_strategy IN ('push', 'pull', 'webhook'))
poll_interval_sec INTEGER
last_fetched_at DATETIME
No schema migration is required — the columns already exist.
get_sources_due_for_poll SQL pattern:
SELECT source_id, adapter_id, poll_interval_sec, last_fetched_at
FROM sources
WHERE poll_strategy = 'pull'
AND poll_interval_sec IS NOT NULL
AND (
last_fetched_at IS NULL
OR datetime(last_fetched_at, '+' || poll_interval_sec || ' seconds') < datetime('now')
)
Import: Add from context_library.storage.models import PollStrategy (already imports Domain).
Existing update_last_fetched_at method is already implemented and used by the pipeline — the Poller will call this after each successful fetch.
Acceptance Criteria
Dependencies
Phase 1: Model Additions (PollStrategy + MessageMetadata)
Parent Issue
Part of #83
Discussion
This work is detailed in discussion 84
Extend DocumentStore.register_source() to accept scheduling parameters and add a get_sources_due_for_poll() query method needed by the Poller scheduler.
Requirements
poll_strategy: PollStrategy = PollStrategy.PULLandpoll_interval_sec: int | None = Noneparameters toDocumentStore.register_source()register_source()must pass these values into thesourcestable columnspoll_strategyandpoll_interval_secINSERT OR IGNOREidempotency behavior must be preservedget_sources_due_for_poll() -> list[dict]method that queries sources where:poll_strategy = 'pull'AND (last_fetched_at IS NULLORdatetime(last_fetched_at, '+' || poll_interval_sec || ' seconds') < datetime('now'))source_id,adapter_id,poll_interval_sec,last_fetched_atDesign Guidance
File to modify:
src/context_library/storage/document_store.pyCurrent
register_sourcesignature (from codebase exploration):New signature:
The SQLite
sourcestable already has these columns (from the existing schema):poll_strategy TEXT NOT NULL CHECK (poll_strategy IN ('push', 'pull', 'webhook'))poll_interval_sec INTEGERlast_fetched_at DATETIMENo schema migration is required — the columns already exist.
get_sources_due_for_pollSQL pattern:Import: Add
from context_library.storage.models import PollStrategy(already importsDomain).Existing
update_last_fetched_atmethod is already implemented and used by the pipeline — the Poller will call this after each successful fetch.Acceptance Criteria
register_source(..., poll_strategy=PollStrategy.PUSH)correctly persists'push'in thesources.poll_strategycolumnregister_source(..., poll_interval_sec=3600)correctly persists3600insources.poll_interval_secregister_source()twice with the samesource_iddoes not raise an error (idempotency preserved)get_sources_due_for_poll()returns a source withlast_fetched_at IS NULLandpoll_strategy='pull'get_sources_due_for_poll()returns a source whoselast_fetched_at + poll_interval_sec < nowget_sources_due_for_poll()does NOT return a source whoselast_fetched_at + poll_interval_sec >= nowget_sources_due_for_poll()does NOT return sources withpoll_strategy='push'get_sources_due_for_poll()does NOT return sources withpoll_interval_sec IS NULLDependencies
Phase 1: Model Additions (PollStrategy + MessageMetadata)
Parent Issue
Part of #83
Discussion
This work is detailed in discussion 84