# scheduler-lite **Repository Path**: jiangyangcz/scheduler-lite ## Basic Information - **Project Name**: scheduler-lite - **Description**: 轻量级任务调度系统 - 零依赖、开箱即用 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2026-05-04 - **Last Updated**: 2026-05-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
零依赖 · 开箱即用 · 5 分钟上手的轻量级任务调度系统
Quick Start • Features • API • Architecture • Contributing
--- ## Why Scheduler Lite? 现代任务调度系统往往依赖 Redis、MySQL、Celery 等重型中间件,搭建和维护成本高。**Scheduler Lite 只需要 Python 3.8+**,一行命令即可启动完整的任务调度服务。 | | Celery | APScheduler | **Scheduler Lite** | |---|---|---|---| | 依赖数 | 15+ | 8+ | **4** | | 需要消息队列 | ✓ | ✗ | ✗ | | 需要数据库 | ✓ 或 Redis | ✗ | ✗ | | HTTP API | 需插件 | ✗ | ✓ 内置 | | 学习曲线 | 陡峭 | 中等 | **低** | | 适合场景 | 大型分布式 | 定时任务 | **通用调度 + API** | ## ✨ Features - **🚀 零依赖启动** — 仅需 `pip install -r requirements.txt`,4 个包 - **🎯 优先级调度** — 4 级优先级(LOW / NORMAL / HIGH / CRITICAL) - **🔄 自动重试** — 任务失败自动重试,可配置次数和间隔 - **📡 RESTful API** — 内置 FastAPI,自动生成 Swagger 文档 - **💾 内存存储** — 无需外部数据库,开箱即用 - **📊 实时统计** — 提交数、完成数、队列大小实时可查 - **🛡️ 线程安全** — 基于 Python 标准库 threading,线程安全设计 ## 🚀 Quick Start ### Requirements - Python 3.8 or higher ### Installation ```bash # Clone git clone https://gitee.com/jiangyangcz/scheduler-lite.git cd scheduler-lite # Install pip install -r requirements.txt # Run python run.py ``` Open your browser: **http://localhost:8000/docs** ### 30-Second Test ```bash # Create a task curl -X POST http://localhost:8000/tasks \ -H "Content-Type: application/json" \ -d '{"name": "Hello World", "func_name": "process_data", "args": [1,2,3]}' # Check the result (replace {task_id}) curl http://localhost:8000/tasks/{task_id} # View stats curl http://localhost:8000/stats ``` ### Python Client ```python import requests api = "http://localhost:8000" # Submit a high-priority task resp = requests.post(f"{api}/tasks", json={ "name": "Daily Report", "func_name": "generate_report", "priority": 3, "kwargs": {"type": "daily"} }) print(resp.json()) # Get stats stats = requests.get(f"{api}/stats").json() print(f"Completed: {stats['total_completed']}/{stats['total_submitted']}") ``` ## 📡 API Reference | Method | Endpoint | Description | |--------|----------|-------------| | `GET` | `/` | Service info | | `GET` | `/health` | Health check | | `POST` | `/tasks` | Create a task | | `GET` | `/tasks` | List tasks (with status filter) | | `GET` | `/tasks/{id}` | Get task detail | | `DELETE` | `/tasks/{id}` | Cancel a task | | `GET` | `/stats` | System statistics | Full API docs: http://localhost:8000/docs (Swagger UI) ### Task Object ```json { "id": "uuid-v4", "name": "My Task", "description": "Optional description", "func_name": "process_data", "args": [1, 2, 3], "kwargs": {"key": "value"}, "priority": 2, "timeout": 300, "retry_count": 3, "retry_delay": 5, "status": "pending|running|success|failed|cancelled", "created_at": "2024-01-01T00:00:00", "started_at": "2024-01-01T00:00:01", "finished_at": "2024-01-01T00:00:02", "result": {}, "error": null, "attempts": 1 } ``` ## 🏗️ Architecture ``` ┌─────────────────────────────────────────┐ │ HTTP Clients │ │ (curl, Python, Postman) │ └─────────────────┬───────────────────────┘ │ ┌─────────────────▼───────────────────────┐ │ FastAPI (src/api/app.py) │ │ RESTful API + Swagger + CORS │ └─────────────────┬───────────────────────┘ │ ┌─────────────────▼───────────────────────┐ │ Scheduler (src/core/scheduler.py) │ │ Thread Pool + Priority Queue │ │ Submit -> Queue -> Workers -> Done │ └─────────────────┬───────────────────────┘ │ ┌─────────────────▼───────────────────────┐ │ MemoryStore (src/core/store.py) │ │ Task CRUD + Status Index + Cleanup │ └─────────────────────────────────────────┘ ``` ### Project Structure ``` scheduler-lite/ ├── run.py # Entry point ├── requirements.txt # Only 4 packages ├── config/ │ └── config.yaml # Configuration ├── src/ │ ├── api/ │ │ └── app.py # FastAPI application │ └── core/ │ ├── task.py # Task data model │ ├── store.py # In-memory storage │ └── scheduler.py # Core scheduler engine └── tests/ └── test_scheduler.py # Unit tests ``` ## 🔧 Configuration Edit `config/config.yaml`: ```yaml scheduler: max_workers: 10 # Number of worker threads max_queue: 1000 # Max queue size task_timeout: 300 # Task timeout (seconds) api: host: "0.0.0.0" port: 8000 debug: false cors_origins: ["*"] ``` Or use command line arguments: ```bash python run.py --port 9000 --workers 20 --debug ``` ## 📈 Roadmap - [x] Core scheduling engine - [x] Priority queue - [x] Auto retry on failure - [x] RESTful API with Swagger - [x] Thread-safe memory store - [ ] Persistent storage (SQLite / JSON file) - [ ] Cron / scheduled tasks - [ ] Web dashboard (simple HTML) - [ ] Task dependency (workflow) - [ ] Webhook notifications ## 🤝 Contributing Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details. 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Commit your changes (`git commit -m 'Add amazing feature'`) 4. Push to the branch (`git push origin feature/amazing-feature`) 5. Open a Pull Request ## 📄 License MIT License - see [LICENSE](LICENSE) for details. ---Built with ❤️ for the open source community