Add hybrid APScheduler + PostgreSQL-based task scheduling system with minute-based execution and priority queue.
Core features:
- Minute-based scheduling with cron-like patterns (-1 = wildcard)
- Priority queue system (1-100, lower = higher priority)
- Concurrent execution (max 5 tasks simultaneously)
- Full REST API for task management (CRUD operations)
- Task execution tracking with audit trail
- API key authentication (Bearer token)
- Health checks and system statistics
Architecture:
- APScheduler runs every minute
- Queries PostgreSQL for tasks scheduled for current minute
- Executes tasks concurrently by priority
- Records execution history in database
Database schema:
- scheduled_tasks: Task definitions/templates
- task_executions: Individual execution records
Technical stack:
- FastAPI for REST API
- APScheduler for scheduling
- PostgreSQL for persistence
- Pydantic for configuration
Endpoints:
- POST/GET/PUT/DELETE /tasks - Task management
- POST /tasks/{name}/trigger - Manual execution
- GET /executions - Execution history
- GET /health - Health check
- GET /stats - System statistics
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
108 lines
3.4 KiB
YAML
108 lines
3.4 KiB
YAML
version: '3.8'
|
|
|
|
# The Scheduler
|
|
# Purpose: System-wide maintenance orchestration - backups, doc mirroring, cleanup, task automation
|
|
# Port: 8090 (API + UI)
|
|
# Network: docker-dataplane
|
|
|
|
services:
|
|
scheduler:
|
|
image: python:3.12-slim
|
|
container_name: scheduler
|
|
restart: unless-stopped
|
|
|
|
command: >
|
|
sh -c "
|
|
echo 'Installing system dependencies...' &&
|
|
apt-get update -qq &&
|
|
apt-get install -y --no-install-recommends git ssh postgresql-client curl docker.io >/dev/null 2>&1 &&
|
|
rm -rf /var/lib/apt/lists/* &&
|
|
echo 'Setting up Python environment...' &&
|
|
if [ ! -f /venv/bin/python ]; then
|
|
echo 'Initializing venv...' &&
|
|
python3 -m venv --clear /venv;
|
|
fi &&
|
|
echo 'Upgrading pip...' &&
|
|
/venv/bin/python -m pip install --upgrade pip --quiet &&
|
|
echo 'Installing dependencies...' &&
|
|
/venv/bin/python -m pip install -r /app/requirements.txt --quiet &&
|
|
echo 'Configuring Git...' &&
|
|
git config --global user.name 'The Librarian' &&
|
|
git config --global user.email 'librarian@portainer-core.local' &&
|
|
echo 'Starting The Scheduler...' &&
|
|
/venv/bin/python -m uvicorn src.main:app --host 0.0.0.0 --port 8090 --workers 1
|
|
"
|
|
|
|
ports:
|
|
- "8090:8090"
|
|
|
|
environment:
|
|
- APP_NAME=The Scheduler
|
|
- APP_VERSION=1.0.0
|
|
- DEBUG=true
|
|
- HOST=0.0.0.0
|
|
- PORT=8090
|
|
- LOG_LEVEL=INFO
|
|
- POSTGRES_HOST=postgres-shared
|
|
- POSTGRES_PORT=5432
|
|
- POSTGRES_DB=scheduler
|
|
- POSTGRES_USER=scheduler_user
|
|
- POSTGRES_PASSWORD=${SCHEDULER_DB_PASSWORD}
|
|
- REDIS_HOST=redis-shared
|
|
- REDIS_PORT=6379
|
|
- REDIS_DB=3
|
|
- GITEA_URL=http://gitea:3000
|
|
- GITEA_USER=${GITEA_LIBRARY_USER}
|
|
- GITEA_PASSWORD=${GITEA_LIBRARY_PASSWORD}
|
|
- GITEA_SSH_HOST=gitea
|
|
- GITEA_SSH_PORT=22
|
|
- BACKUP_RETENTION_DAILY=7
|
|
- BACKUP_RETENTION_WEEKLY=4
|
|
- BACKUP_RETENTION_MONTHLY=12
|
|
- DOCS_MIRROR_PATH=/docs-mirror
|
|
- DOCS_CHECK_INTERVAL=21600
|
|
- SCHEDULER_API_KEY=${SCHEDULER_API_KEY}
|
|
- PYTHONPATH=/app
|
|
|
|
volumes:
|
|
- /home/jpmschweitzer/Projects/portainer-core/services/scheduler:/app
|
|
- /home/jpmschweitzer/docker-data/scheduler/venv:/venv
|
|
- /home/jpmschweitzer/docker-data/scheduler/logs:/app/logs
|
|
- /home/jpmschweitzer/docker-data/scheduler/task-data:/app/task-data
|
|
- /home/jpmschweitzer/docker-data/scheduler/ssh:/root/.ssh:ro
|
|
- /mnt/media/library/docs-mirror:/docs-mirror
|
|
- /mnt/media/backups/library:/backups
|
|
- /var/run/docker.sock:/var/run/docker.sock:ro
|
|
- /home/jpmschweitzer/docker-data/postgres-shared:/postgres-data:ro
|
|
# For config backups (read-only sources)
|
|
- /home/jpmschweitzer/docker-data:/data/docker-data:ro
|
|
- /home/jpmschweitzer/.config/code-server:/data/code-server-config:ro
|
|
# For config backups (write destination)
|
|
- /mnt/media/backups/docker-configs:/backups/docker-configs
|
|
|
|
networks:
|
|
- docker-dataplane
|
|
|
|
deploy:
|
|
resources:
|
|
limits:
|
|
cpus: '0.5'
|
|
memory: 1G
|
|
reservations:
|
|
memory: 256M
|
|
|
|
labels:
|
|
- "com.centurylinklabs.watchtower.enable=true"
|
|
|
|
healthcheck:
|
|
test: ["CMD", "curl", "-f", "http://localhost:8090/health"]
|
|
interval: 30s
|
|
timeout: 10s
|
|
retries: 3
|
|
start_period: 90s
|
|
|
|
networks:
|
|
docker-dataplane:
|
|
external: true
|
|
name: docker-dataplane
|