feat: continuous polling loop for Schiphol producer #1
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: peter/schiphol#1
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
The producer currently exits after completing a single Poll — it fetches all pages from the Schiphol API, publishes one Snapshot per Flight to Kafka, and stops. This means the Kafka topic goes stale immediately after the first run. For consumers (such as the planned database writer) to always have current flight data, the producer must continuously re-poll and keep the topic up to date.
Solution
Refactor the producer so it runs as a long-lived process: it polls the Schiphol API once, publishes Snapshots for all Flights, waits 5 minutes, then polls again — indefinitely. The HTTP session, Kafka engine, and OpenTelemetry tracer are initialised once at startup and reused across Polls.
User Stories
Implementation Decisions
start()into a standalone asyncpoll()function.poll()accepts the HTTP session, Kafka stream engine, API settings, Kafka settings, and tracer as parameters and returns the number of Flights published.start()is refactored to: (1) initialise OTel, create Kafka engine, create HTTP session; (2) loop forever — callpoll(), log the result, sleep 5 minutes, repeat.aiorunshutdown callback; no changes needed there.poll_cycle— carrying aflights.publishedattribute with the count.Testing Decisions
A good test exercises the observable output of
poll()— the Kafka messages sent and the return value — without asserting on internal implementation details like pagination cursor management or span creation.What to test (at the
poll()seam):link: rel="next"header,poll()publishes N messages to Kafka and returns N.link: rel="next"),poll()publishes the combined flight count across both pages.poll()propagates the exception.Prior art: None — this will be the first test in the codebase. Use
pytestwithpytest-asynciofor async test support. Mock the HTTP session with a simple stub class (notunittest.mock) that returns pre-built response objects. Mock the Kafka engine'ssend()method to capture calls.Out of Scope
Further Notes
ADR-0001 records that Kafka messages are Snapshots, not immutable events. ADR-0002 records the decision to use a continuous process rather than a cron job. Both are relevant background for this feature.
The
middelware.pyfile (note: typo in filename) contains consumer-side deserialization middleware. It is not touched by this feature.