Florian 8555be3f53
All checks were successful
Build & Publish to GHCR / build (push) Successful in 36s
test.py
2025-11-06 20:59:40 +01:00
2025-11-06 17:38:58 +01:00
2025-11-06 20:59:40 +01:00
2025-10-11 17:57:10 +02:00
2025-11-04 10:05:22 +01:00
2025-10-19 17:02:39 +02:00

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

pip install -r requirements.txt

Running the Service

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

GET /royalroad

Response:

{
  "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:

{
  "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:

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
Description
Fetches new RR chapter data
Readme 102 KiB
Languages
Python 96.2%
Dockerfile 3.8%