Conversation
- Create `worker.py` to process IoT payloads from Redis `seismic_events` queue - Implement safe ORM mapping for `Misuration` PostGIS inserts - Add fallback Dead Letter Queue (`seismic_events_dlq`) for database commit failures - Enforce token-based authentication on FastAPI WebSocket endpoints - Fix `stress_test.py` asyncio sleep pacing for accurate load generation - Add `PYTHONUNBUFFERED=1` and `flush=True` to worker for real-time Docker logging Closes #51, Closes #54, Closes #55, Closes #56, Closes #57, Closes #58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR introduces the core asynchronous data persistence layer for the QuakeGuard backend, alongside critical security updates for the mobile application's real-time feeds.
Incoming IoT payloads validated by the FastAPI gateway are now reliably popped from the Redis message broker and batch-inserted into the PostGIS database via a dedicated Python background worker.
Changes Made
src/worker.pywith a continuousbrpoploop listening to theseismic_eventsqueue. (Createworker.pyin thesrc/directory. #55, Implement a continuous loop that reads from the Redisseismic_eventsqueue. #56)MisurationSQLAlchemy ORM, ensuringdevice_timestampmismatches do not crash the insert. (Parse the JSON payload and execute anINSERTstatement into the PostGISmeasurementstable. #57)seismic_events_dlqfor manual recovery. (Implement error handling (e.g., if PostGIS goes down, push the payload back to a Dead Letter Queue or retry). #58)/ws/alertsendpoint. Connections without a validMOBILE_WS_TOKENare now rejected withWS_1008_POLICY_VIOLATION.tests/stress_test.pywhere a 1.5s sleep delay caused the load test to hang. Adjusted to0.025sto properly simulate 40 req/sec and interact correctly with the Redis Rate Limiter.PYTHONUNBUFFERED=1and forcingflush=Trueon worker logs for immediate visibility.Testing Performed
stress_test.py(Phase 1).misurationtable.Related Issues
Closes #51
Closes #54
Closes #55
Closes #56
Closes #57
Closes #58