diff --git a/README.md b/README.md index dc52082..bfdf397 100644 --- a/README.md +++ b/README.md @@ -7,52 +7,88 @@ ## Features -- Fetches the latest chapters from Royalroad RSS feeds. +- **RSS Feed Monitoring**: Parses Royal Road RSS feeds to detect new chapter releases +- **Automatic Updates**: Updates database with latest chapter numbers +- **Retry Logic**: Built-in retry mechanisms for network failures with exponential backoff +- **Prometheus Metrics**: Request counters and performance monitoring on port 9000 -- Updates the database when new chapters are released. +## Prerequisites -- Sends push notifications for new chapters. +- Python 3.10+ +- MySQL database +- Backend notification service (for sending push notifications) +- Royal Road story IDs -- Prometheus metrics integrated for monitoring request counts. +## Installation +```bash +pip install -r requirements.txt +``` -## Endpoints -### GET `/royalroad` -- Checks for new chapters for all active stories in the database. -- Updates the `lastChapter` field in the database. -- Sends notifications if a new chapter is found. -- Response: +## Running the Service + +```bash +python main.py +``` + +This starts two servers: +- **Main API**: `http://0.0.0.0:5000` - Handles chapter check requests +- **Metrics Server**: `http://0.0.0.0:9000/metrics` - Prometheus metrics endpoint + +### API Endpoint + +#### Check for New Chapters + +```http +GET /royalroad +``` + +**Response:** ```json { "status": "checked" } ``` -## Requirements +**Behavior:** +1. Fetches all active stories from the database +2. Queries Royal Road RSS feed for each story +3. Compares latest chapter with stored chapter number +4. Updates database if new chapter is detected +5. Sends notification to backend service -- Python 3.12+ +**Error Responses:** +- `404`: Feed not found or has no entries +- `500`: Internal server error during processing +- `503`: Notification service unavailable after retries -- MySQL database +## Notification Format -- Python packages from requirements.txt +Messages sent to the backend service: -## Configuration +```json +{ + "receipent_user_id": 1, + "message": { + "title": "New Life As A Max Level Archmage", + "body": "Chapter 68 has been released", + "link": "https://www.royalroad.com/fiction/118891/new-life-as-a-max-level-archmage/chapter/2683797/68-carve", + "category": "royal-road", + "timestamp": 1729339200 + } +} +``` -**Environment variables:** +**Headers:** +```http +X-API-Key-Internal: +Content-Type: application/json +``` -- `LOG_LEVEL` (DEBUG, INFO, WARNING, ERROR, CRITICAL) +## Monitoring -- Database credentials: `db_host`, `db_username`, `db_password`, `db_database` +### Prometheus Metrics -- `api_key` +Available at `http://localhost:9000/metrics`: -- `backend_api_url` - - -## Metrics - -Metrics are exposed on port `9000` for Prometheus - -## Running the Service - -- Inside the `src` folder `python main.py` +- `http_requests_total{method, path, status}`: Request counter with labels \ No newline at end of file