This commit is contained in:
parent
7da37f71de
commit
14a61218ac
94
README.md
94
README.md
@ -7,52 +7,88 @@
|
|||||||
|
|
||||||
## Features
|
## 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
|
## Running the Service
|
||||||
### GET `/royalroad`
|
|
||||||
- Checks for new chapters for all active stories in the database.
|
```bash
|
||||||
- Updates the `lastChapter` field in the database.
|
python main.py
|
||||||
- Sends notifications if a new chapter is found.
|
```
|
||||||
- Response:
|
|
||||||
|
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
|
```json
|
||||||
{
|
{
|
||||||
"status": "checked"
|
"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: <api_key>
|
||||||
|
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`
|
- `http_requests_total{method, path, status}`: Request counter with labels
|
||||||
|
|
||||||
|
|
||||||
## Metrics
|
|
||||||
|
|
||||||
Metrics are exposed on port `9000` for Prometheus
|
|
||||||
|
|
||||||
## Running the Service
|
|
||||||
|
|
||||||
- Inside the `src` folder `python main.py`
|
|
||||||
Loading…
x
Reference in New Issue
Block a user