Florian 14a61218ac
All checks were successful
Build & Publish to GHCR / build (push) Successful in 30s
Rewrote readme
2025-10-19 17:02:39 +02:00

94 lines
2.1 KiB
Markdown

# Service: Royalroad Chapters
## Overview
`service-royalroad-chapters` is a FastAPI-based webserver that monitors Royalroad stories for new chapters and sends notifications data to `backend-api-internal`.
## Features
- **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
## Prerequisites
- Python 3.10+
- MySQL database
- Backend notification service (for sending push notifications)
- Royal Road story IDs
## Installation
```bash
pip install -r requirements.txt
```
## 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"
}
```
**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
**Error Responses:**
- `404`: Feed not found or has no entries
- `500`: Internal server error during processing
- `503`: Notification service unavailable after retries
## Notification Format
Messages sent to the backend service:
```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
}
}
```
**Headers:**
```http
X-API-Key-Internal: <api_key>
Content-Type: application/json
```
## Monitoring
### Prometheus Metrics
Available at `http://localhost:9000/metrics`:
- `http_requests_total{method, path, status}`: Request counter with labels