|
| 1 | +# Distributed Task Runner  |
| 2 | + |
| 3 | +<!-- Centered badges --> |
| 4 | +<p align="center"> |
| 5 | + <a href="https://golang.org/dl/"><img src="https://img.shields.io/badge/Go-1.20%2B-blue" alt="Go Version"></a> |
| 6 | + <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-16%2B-green" alt="Node.js"></a> |
| 7 | + <a href="https://raw.githubusercontent.com/HERALDEXX/distributed-task-runner/refs/heads/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT License"></a> |
| 8 | +</p> |
| 9 | + |
| 10 | +A lightweight Distributed Task Runner with a Go backend and React frontend. |
| 11 | +Submit shell commands or scripts as tasks (jobs), execute them asynchronously, and track their status and output via a modern web UI. |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## 📚 Table of Contents |
| 16 | + |
| 17 | +- [🚀 Quick Start](#quick-start) |
| 18 | +- [Features](#features) |
| 19 | +- [Project Structure](#project-structure) |
| 20 | +- [Prerequisites](#prerequisites) |
| 21 | + - [Tech Stack](#tech-stack) |
| 22 | +- [Backend API](#backend-api) |
| 23 | +- [Frontend Usage](#frontend-usage) |
| 24 | +- [Notes](#notes) |
| 25 | +- [Screenshots](#screenshots) |
| 26 | +- [Contributing](#contributing) |
| 27 | +- [Future Potential Improvements](#future-potential-improvements) |
| 28 | +- [License](https://raw.githubusercontent.com/HERALDEXX/distributed-task-runner/refs/heads/main/LICENSE) |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Quick Start |
| 33 | + |
| 34 | +### Prerequisite: Install Go |
| 35 | + |
| 36 | +If you don't have Go installed, download and install it from the official website: |
| 37 | + |
| 38 | +[https://go.dev/dl/](https://go.dev/dl/) |
| 39 | + |
| 40 | +--- |
| 41 | + |
| 42 | +### Backend (Cross-platform) |
| 43 | + |
| 44 | +```bash |
| 45 | +cd backend |
| 46 | +``` |
| 47 | + |
| 48 | +#### On Windows (PowerShell or Command Prompt): |
| 49 | + |
| 50 | +Run the scheduler using the batch file (this will build and run the backend): |
| 51 | + |
| 52 | +```cmd |
| 53 | +./dev.bat |
| 54 | +``` |
| 55 | + |
| 56 | +> **Note:** The first time you run the backend, Windows may show a firewall prompt. This is normal—allow access so the server can listen on port 8080. |
| 57 | +
|
| 58 | +#### On macOS/Linux: |
| 59 | + |
| 60 | +```bash |
| 61 | +go run . |
| 62 | +``` |
| 63 | + |
| 64 | +> **Note:** On macOS/Linux, you typically will NOT see a firewall prompt. If you do, allow access so the server can listen on port 8080. |
| 65 | +
|
| 66 | +Server runs on [http://localhost:8080](http://localhost:8080) |
| 67 | + |
| 68 | +### Frontend (Cross-platform) |
| 69 | + |
| 70 | +```bash |
| 71 | +cd frontend |
| 72 | +``` |
| 73 | + |
| 74 | +```bash |
| 75 | +npm install |
| 76 | +``` |
| 77 | + |
| 78 | +```bash |
| 79 | +npm run dev |
| 80 | +``` |
| 81 | + |
| 82 | +Opens on [http://localhost:5173](http://localhost:5173) |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## Features |
| 87 | + |
| 88 | +- 🧠 Asynchronous task execution via worker pool |
| 89 | +- 💾 Persistent storage with [`jobs.json`](backend/jobs.json) |
| 90 | +- 🔁 Retry mechanism for failed tasks (up to 3 attempts) |
| 91 | +- 🧪 Track status: `pending`, `running`, `completed`, `failed` |
| 92 | +- 🧩 RESTful API in Go |
| 93 | +- 🎨 React + TypeScript UI for submitting and monitoring tasks |
| 94 | +- 🧹 Clear history functionality |
| 95 | +- 🔓 CORS support for frontend-backend integration |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +## Project Structure |
| 100 | + |
| 101 | +``` |
| 102 | +distributed-task-runner/ |
| 103 | +├── backend/ |
| 104 | +│ ├── main.go |
| 105 | +│ ├── handlers.go |
| 106 | +│ ├── jobs.go |
| 107 | +│ └── ... |
| 108 | +├── frontend/ |
| 109 | +│ ├── src/ |
| 110 | +│ │ ├── App.tsx |
| 111 | +│ │ ├── JobSubmitter.tsx |
| 112 | +│ │ ├── JobList.tsx |
| 113 | +│ │ └── ... |
| 114 | +│ ├── vite.config.ts |
| 115 | +│ └── ... |
| 116 | +├── jobs.json # stores job data |
| 117 | +└── README.md |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Prerequisites |
| 123 | + |
| 124 | +### Tech Stack |
| 125 | + |
| 126 | +| Technology | Version/Requirement | |
| 127 | +| ---------- | ------------------- | |
| 128 | +| Go | 1.20+ | |
| 129 | +| Node.js | 16+ | |
| 130 | +| npm/yarn | Any | |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Backend API |
| 135 | + |
| 136 | +### Endpoints |
| 137 | + |
| 138 | +- `POST /jobs` — Enqueue a task `{ "payload": "your-command" }` |
| 139 | +- `GET /jobs` — List all tasks |
| 140 | +- `GET /jobs/{id}` — Get a specific task |
| 141 | +- `DELETE /jobs/clear` — Clear all task history |
| 142 | + |
| 143 | +#### Example: Submit a task |
| 144 | + |
| 145 | +```bash |
| 146 | +curl -X POST http://localhost:8080/jobs -H "Content-Type: application/json" -d '{"payload": "echo Hello"}' |
| 147 | +``` |
| 148 | + |
| 149 | +Response: |
| 150 | + |
| 151 | +```json |
| 152 | +{ |
| 153 | + "id": "abc123", |
| 154 | + "payload": "echo Hello", |
| 155 | + "status": "pending", |
| 156 | + "attempts": 0, |
| 157 | + "created_at": "2025-08-02T14:32:47Z", |
| 158 | + "updated_at": "2025-08-02T14:32:47Z" |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +#### Example: Get All tasks |
| 163 | + |
| 164 | +```bash |
| 165 | +curl http://localhost:8080/jobs |
| 166 | +``` |
| 167 | + |
| 168 | +Response: |
| 169 | + |
| 170 | +```json |
| 171 | +[ |
| 172 | + { |
| 173 | + "id": "abc123", |
| 174 | + "payload": "echo Hello", |
| 175 | + "status": "completed", |
| 176 | + "attempts": 1, |
| 177 | + "created_at": "2025-08-02T14:32:47Z", |
| 178 | + "updated_at": "2025-08-02T14:33:01Z", |
| 179 | + "output": "Hello\n" |
| 180 | + } |
| 181 | +] |
| 182 | +``` |
| 183 | + |
| 184 | +#### Example: Get task by ID |
| 185 | + |
| 186 | +```bash |
| 187 | +curl http://localhost:8080/jobs/<job_id> |
| 188 | +``` |
| 189 | + |
| 190 | +Response: |
| 191 | + |
| 192 | +```json |
| 193 | +{ |
| 194 | + "id": "abc123", |
| 195 | + "payload": "echo Hello", |
| 196 | + "status": "completed", |
| 197 | + "attempts": 1, |
| 198 | + "created_at": "2025-08-02T14:32:47Z", |
| 199 | + "updated_at": "2025-08-02T14:33:01Z", |
| 200 | + "output": "Hello\n" |
| 201 | +} |
| 202 | +``` |
| 203 | + |
| 204 | +#### Example: Clear task History |
| 205 | + |
| 206 | +```bash |
| 207 | +curl -X DELETE http://localhost:8080/jobs/clear |
| 208 | +``` |
| 209 | + |
| 210 | +--- |
| 211 | + |
| 212 | +## Frontend Usage |
| 213 | + |
| 214 | +- Submit tasks (jobs) and monitor their status in real time. |
| 215 | +- View job history, including command, status (color-coded), and timestamps. |
| 216 | +- Use **Clear History** to delete all jobs. |
| 217 | +- Frontend proxies requests to the backend (see [`vite.config.ts`](frontend/vite.config.ts)). |
| 218 | + |
| 219 | +--- |
| 220 | + |
| 221 | +## Notes |
| 222 | + |
| 223 | +- Commands run using `cmd` (on Windows) or `sh` (on Unix). |
| 224 | +- Backend retries failed tasks (max 3). |
| 225 | +- Data is written to [`jobs.json`](backend/jobs.json) after execution. |
| 226 | +- CORS enabled for frontend access. |
| 227 | + |
| 228 | +--- |
| 229 | + |
| 230 | +## Screenshots |
| 231 | + |
| 232 | +### 🏠 Homepage (Submit Job) |
| 233 | + |
| 234 | + |
| 235 | + |
| 236 | +--- |
| 237 | + |
| 238 | +### ✅ Job Successfully Submitted |
| 239 | + |
| 240 | + |
| 241 | + |
| 242 | +--- |
| 243 | + |
| 244 | +### 📜 Job History Page |
| 245 | + |
| 246 | + |
| 247 | + |
| 248 | +--- |
| 249 | + |
| 250 | +## Contributing |
| 251 | + |
| 252 | +Contributions are welcome! To contribute: |
| 253 | + |
| 254 | +1. Fork the repo |
| 255 | +2. Create a new branch (`git checkout -b feature/your-feature`) |
| 256 | +3. Commit your changes |
| 257 | +4. Push to your branch |
| 258 | +5. Open a Pull Request |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | +## Future Potential Improvements |
| 263 | + |
| 264 | +- [ ] Auth (JWT or session-based) |
| 265 | +- [ ] SSE/WebSocket for real-time task (job) updates |
| 266 | +- [ ] Dockerize backend and frontend |
| 267 | +- [ ] Pagination for large task lists |
| 268 | +- [ ] Task expiration / TTL |
| 269 | +- [ ] Worker monitoring UI |
| 270 | + |
| 271 | +--- |
| 272 | + |
| 273 | +<div align="center"> |
| 274 | + <p> |
| 275 | + <strong style="font-weight: bold;">MIT Licensed • © 2025 Herald Inyang •</strong> |
| 276 | + <a href="https://github.com/HERALDEXX" target="_blank"> |
| 277 | + <img src="https://img.shields.io/badge/GitHub-HERALDEXX-000?style=flat-square&logo=github" alt="GitHub Badge" style="vertical-align: middle;" /> |
| 278 | + </a> |
| 279 | + </p> |
| 280 | + <p> |
| 281 | + <a href="https://raw.githubusercontent.com/HERALDEXX/distributed-task-runner/refs/heads/main/LICENSE" target="_blank"> |
| 282 | + <img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="Click to View MIT License" style="vertical-align: middle;" /> |
| 283 | + </a> |
| 284 | + </p> |
| 285 | +</div> |
| 286 | + |
| 287 | +--- |
0 commit comments