clirey 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clirey-0.1.0/PKG-INFO +167 -0
- clirey-0.1.0/README.md +133 -0
- clirey-0.1.0/clirey/__init__.py +3 -0
- clirey-0.1.0/clirey/cli.py +270 -0
- clirey-0.1.0/clirey/config.py +76 -0
- clirey-0.1.0/clirey/core/broker.py +109 -0
- clirey-0.1.0/clirey/core/client.py +288 -0
- clirey-0.1.0/clirey/core/events.py +208 -0
- clirey-0.1.0/clirey/core/models.py +90 -0
- clirey-0.1.0/clirey/mock/simulator.py +208 -0
- clirey-0.1.0/clirey/ui/console.py +117 -0
- clirey-0.1.0/clirey/ui/dashboard.py +195 -0
- clirey-0.1.0/clirey/ui/tables.py +167 -0
- clirey-0.1.0/clirey.egg-info/PKG-INFO +167 -0
- clirey-0.1.0/clirey.egg-info/SOURCES.txt +22 -0
- clirey-0.1.0/clirey.egg-info/dependency_links.txt +1 -0
- clirey-0.1.0/clirey.egg-info/entry_points.txt +2 -0
- clirey-0.1.0/clirey.egg-info/requires.txt +7 -0
- clirey-0.1.0/clirey.egg-info/top_level.txt +1 -0
- clirey-0.1.0/pyproject.toml +53 -0
- clirey-0.1.0/setup.cfg +4 -0
- clirey-0.1.0/tests/test_cli.py +29 -0
- clirey-0.1.0/tests/test_config.py +31 -0
- clirey-0.1.0/tests/test_models.py +43 -0
clirey-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: clirey
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A powerful CLI & live terminal monitor for Celery with just a broker URL
|
|
5
|
+
Author-email: Inzam <your-email@example.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/inzam/clirey
|
|
8
|
+
Project-URL: Documentation, https://github.com/inzam/clirey#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/inzam/clirey
|
|
10
|
+
Project-URL: Issues, https://github.com/inzam/clirey/issues
|
|
11
|
+
Keywords: celery,cli,monitoring,redis,rabbitmq,tui,rich,dashboard
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: System :: Monitoring
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
Requires-Dist: celery>=5.3.0
|
|
28
|
+
Requires-Dist: redis>=5.0.0
|
|
29
|
+
Requires-Dist: kombu>=5.3.0
|
|
30
|
+
Requires-Dist: amqp>=5.2.0
|
|
31
|
+
Requires-Dist: rich>=13.0.0
|
|
32
|
+
Requires-Dist: typer>=0.12.0
|
|
33
|
+
Requires-Dist: pydantic>=2.0.0
|
|
34
|
+
|
|
35
|
+
# โก Clirey
|
|
36
|
+
|
|
37
|
+
**Clirey** is a modern, rich CLI tool and interactive live terminal dashboard (TUI) for monitoring and controlling **Celery** clusters using **only the Celery Broker URL**โwith zero dependencies on your worker application code, task definitions, or backend database.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## โจ Features
|
|
42
|
+
|
|
43
|
+
- **No Task Code Required**: Connects to the Celery cluster solely via the Broker URL (`redis://`, `rediss://`, `amqp://`, `pyamqp://`).
|
|
44
|
+
- **๐ฅ๏ธ Live Interactive TUI Dashboard (`clirey top` / `clirey monitor`)**:
|
|
45
|
+
- **Cluster Overview**: Online/Offline workers count, active running tasks, throughput (events/sec), total processed, failure counts.
|
|
46
|
+
- **Worker Matrix**: Worker node names, status, pool concurrency, OS load averages (1m, 5m, 15m), and uptime.
|
|
47
|
+
- **Active Tasks**: Real-time running tasks, executing worker node, runtime duration, and arguments.
|
|
48
|
+
- **Queues & Backlog**: Worker consumers count and direct broker pending message depth (e.g. Redis `LLEN` / RabbitMQ queue declare).
|
|
49
|
+
- **Live Event Stream**: Real-time event ticker (succeeded, failed, retried, started, worker heartbeats) with durations and exception details.
|
|
50
|
+
- **โก Scriptable One-Shot Commands**:
|
|
51
|
+
- `clirey workers`: List active worker nodes, pool configs, uptime, and load averages.
|
|
52
|
+
- `clirey tasks`: View currently active, scheduled (ETA), or reserved tasks.
|
|
53
|
+
- `clirey queues`: Broker queue depths and worker subscription mapping.
|
|
54
|
+
- `clirey events`: Live streaming event tail on your console.
|
|
55
|
+
- `clirey ping`: Ping all active workers and calculate cluster round-trip latency.
|
|
56
|
+
- `clirey task <task_id>`: Inspect task status and worker assignment.
|
|
57
|
+
- `clirey revoke <task_id>`: Remotely revoke or terminate running tasks.
|
|
58
|
+
- **๐ฎ Built-in Simulator (`clirey demo`)**: Run and test the live terminal dashboard instantly without needing a live Celery cluster.
|
|
59
|
+
- **๐ Automatic Credential Masking**: Passwords and secrets in broker connection strings are automatically masked in terminal outputs.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ๐ Installation
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Clone the repository
|
|
67
|
+
git clone https://github.com/your-org/clirey.git
|
|
68
|
+
cd clirey
|
|
69
|
+
|
|
70
|
+
# Create virtual environment and install
|
|
71
|
+
python -m venv .venv
|
|
72
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
73
|
+
pip install -e .
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## โ๏ธ Broker URL Configuration
|
|
79
|
+
|
|
80
|
+
You can provide the broker URL in any of the following ways (in priority order):
|
|
81
|
+
|
|
82
|
+
1. **CLI Option**: `--broker` or `-b`
|
|
83
|
+
```bash
|
|
84
|
+
clirey top -b redis://:password@10.0.1.50:6379/0
|
|
85
|
+
```
|
|
86
|
+
2. **Environment Variable**: `CELERY_BROKER_URL` or `CLIREY_BROKER_URL` or `REDIS_URL`
|
|
87
|
+
```bash
|
|
88
|
+
export CELERY_BROKER_URL="amqp://guest:guest@localhost:5672//"
|
|
89
|
+
clirey top
|
|
90
|
+
```
|
|
91
|
+
3. **Config File (`.clirey.json` or `~/.clirey.json`)**:
|
|
92
|
+
```json
|
|
93
|
+
{
|
|
94
|
+
"broker_url": "redis://localhost:6379/0"
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
## ๐ Usage Guide
|
|
101
|
+
|
|
102
|
+
### 1. Launch Live Interactive Terminal Dashboard
|
|
103
|
+
```bash
|
|
104
|
+
clirey top
|
|
105
|
+
# or with explicit broker
|
|
106
|
+
clirey top --broker redis://localhost:6379/0 --refresh 1.5
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### 2. Try the Demo Simulator
|
|
110
|
+
```bash
|
|
111
|
+
clirey demo
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 3. List Connected Workers
|
|
115
|
+
```bash
|
|
116
|
+
clirey workers
|
|
117
|
+
```
|
|
118
|
+
Output:
|
|
119
|
+
```
|
|
120
|
+
Active Celery Workers
|
|
121
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโ
|
|
122
|
+
โ Worker Node โ Status โ Active โ Processed โ Concurrency โ Pool โ Load Avg (1,5,15m) โ Uptime โ Queues โ
|
|
123
|
+
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
|
|
124
|
+
โ celery@worker-1.prod โ โ ONLINE โ 2 โ 14,320 โ 8 โ prefork โ 0.45, 0.38, 0.30 โ 23h 40m โ default โ
|
|
125
|
+
โ celery@worker-2.prod โ โ ONLINE โ 1 โ 9,812 โ 4 โ gevent โ 0.12, 0.15, 0.18 โ 10h 15m โ reports โ
|
|
126
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโ
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 4. Inspect Queues & Backlog
|
|
130
|
+
```bash
|
|
131
|
+
clirey queues
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 5. List Active & Scheduled Tasks
|
|
135
|
+
```bash
|
|
136
|
+
clirey tasks --type active
|
|
137
|
+
clirey tasks --type scheduled
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 6. Stream Live Events
|
|
141
|
+
```bash
|
|
142
|
+
clirey events
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 7. Ping Active Workers
|
|
146
|
+
```bash
|
|
147
|
+
clirey ping
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 8. Revoke / Terminate a Task
|
|
151
|
+
```bash
|
|
152
|
+
clirey revoke <task-uuid> --terminate --signal SIGTERM
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## ๐งช Running Tests
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pytest
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## ๐ License
|
|
166
|
+
|
|
167
|
+
MIT License
|
clirey-0.1.0/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# โก Clirey
|
|
2
|
+
|
|
3
|
+
**Clirey** is a modern, rich CLI tool and interactive live terminal dashboard (TUI) for monitoring and controlling **Celery** clusters using **only the Celery Broker URL**โwith zero dependencies on your worker application code, task definitions, or backend database.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## โจ Features
|
|
8
|
+
|
|
9
|
+
- **No Task Code Required**: Connects to the Celery cluster solely via the Broker URL (`redis://`, `rediss://`, `amqp://`, `pyamqp://`).
|
|
10
|
+
- **๐ฅ๏ธ Live Interactive TUI Dashboard (`clirey top` / `clirey monitor`)**:
|
|
11
|
+
- **Cluster Overview**: Online/Offline workers count, active running tasks, throughput (events/sec), total processed, failure counts.
|
|
12
|
+
- **Worker Matrix**: Worker node names, status, pool concurrency, OS load averages (1m, 5m, 15m), and uptime.
|
|
13
|
+
- **Active Tasks**: Real-time running tasks, executing worker node, runtime duration, and arguments.
|
|
14
|
+
- **Queues & Backlog**: Worker consumers count and direct broker pending message depth (e.g. Redis `LLEN` / RabbitMQ queue declare).
|
|
15
|
+
- **Live Event Stream**: Real-time event ticker (succeeded, failed, retried, started, worker heartbeats) with durations and exception details.
|
|
16
|
+
- **โก Scriptable One-Shot Commands**:
|
|
17
|
+
- `clirey workers`: List active worker nodes, pool configs, uptime, and load averages.
|
|
18
|
+
- `clirey tasks`: View currently active, scheduled (ETA), or reserved tasks.
|
|
19
|
+
- `clirey queues`: Broker queue depths and worker subscription mapping.
|
|
20
|
+
- `clirey events`: Live streaming event tail on your console.
|
|
21
|
+
- `clirey ping`: Ping all active workers and calculate cluster round-trip latency.
|
|
22
|
+
- `clirey task <task_id>`: Inspect task status and worker assignment.
|
|
23
|
+
- `clirey revoke <task_id>`: Remotely revoke or terminate running tasks.
|
|
24
|
+
- **๐ฎ Built-in Simulator (`clirey demo`)**: Run and test the live terminal dashboard instantly without needing a live Celery cluster.
|
|
25
|
+
- **๐ Automatic Credential Masking**: Passwords and secrets in broker connection strings are automatically masked in terminal outputs.
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## ๐ Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Clone the repository
|
|
33
|
+
git clone https://github.com/your-org/clirey.git
|
|
34
|
+
cd clirey
|
|
35
|
+
|
|
36
|
+
# Create virtual environment and install
|
|
37
|
+
python -m venv .venv
|
|
38
|
+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
|
39
|
+
pip install -e .
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## โ๏ธ Broker URL Configuration
|
|
45
|
+
|
|
46
|
+
You can provide the broker URL in any of the following ways (in priority order):
|
|
47
|
+
|
|
48
|
+
1. **CLI Option**: `--broker` or `-b`
|
|
49
|
+
```bash
|
|
50
|
+
clirey top -b redis://:password@10.0.1.50:6379/0
|
|
51
|
+
```
|
|
52
|
+
2. **Environment Variable**: `CELERY_BROKER_URL` or `CLIREY_BROKER_URL` or `REDIS_URL`
|
|
53
|
+
```bash
|
|
54
|
+
export CELERY_BROKER_URL="amqp://guest:guest@localhost:5672//"
|
|
55
|
+
clirey top
|
|
56
|
+
```
|
|
57
|
+
3. **Config File (`.clirey.json` or `~/.clirey.json`)**:
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"broker_url": "redis://localhost:6379/0"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## ๐ Usage Guide
|
|
67
|
+
|
|
68
|
+
### 1. Launch Live Interactive Terminal Dashboard
|
|
69
|
+
```bash
|
|
70
|
+
clirey top
|
|
71
|
+
# or with explicit broker
|
|
72
|
+
clirey top --broker redis://localhost:6379/0 --refresh 1.5
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### 2. Try the Demo Simulator
|
|
76
|
+
```bash
|
|
77
|
+
clirey demo
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. List Connected Workers
|
|
81
|
+
```bash
|
|
82
|
+
clirey workers
|
|
83
|
+
```
|
|
84
|
+
Output:
|
|
85
|
+
```
|
|
86
|
+
Active Celery Workers
|
|
87
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโณโโโโโโโโโโโโณโโโโโโโโโโโโโโณโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโ
|
|
88
|
+
โ Worker Node โ Status โ Active โ Processed โ Concurrency โ Pool โ Load Avg (1,5,15m) โ Uptime โ Queues โ
|
|
89
|
+
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
|
|
90
|
+
โ celery@worker-1.prod โ โ ONLINE โ 2 โ 14,320 โ 8 โ prefork โ 0.45, 0.38, 0.30 โ 23h 40m โ default โ
|
|
91
|
+
โ celery@worker-2.prod โ โ ONLINE โ 1 โ 9,812 โ 4 โ gevent โ 0.12, 0.15, 0.18 โ 10h 15m โ reports โ
|
|
92
|
+
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโ
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### 4. Inspect Queues & Backlog
|
|
96
|
+
```bash
|
|
97
|
+
clirey queues
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 5. List Active & Scheduled Tasks
|
|
101
|
+
```bash
|
|
102
|
+
clirey tasks --type active
|
|
103
|
+
clirey tasks --type scheduled
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 6. Stream Live Events
|
|
107
|
+
```bash
|
|
108
|
+
clirey events
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 7. Ping Active Workers
|
|
112
|
+
```bash
|
|
113
|
+
clirey ping
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 8. Revoke / Terminate a Task
|
|
117
|
+
```bash
|
|
118
|
+
clirey revoke <task-uuid> --terminate --signal SIGTERM
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## ๐งช Running Tests
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
pytest
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## ๐ License
|
|
132
|
+
|
|
133
|
+
MIT License
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
# Ensure UTF-8 output streams on Windows
|
|
6
|
+
if sys.platform.startswith("win"):
|
|
7
|
+
try:
|
|
8
|
+
if sys.stdout and hasattr(sys.stdout, "reconfigure"):
|
|
9
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
10
|
+
if sys.stderr and hasattr(sys.stderr, "reconfigure"):
|
|
11
|
+
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
|
|
12
|
+
except Exception:
|
|
13
|
+
pass
|
|
14
|
+
|
|
15
|
+
import time
|
|
16
|
+
import typer
|
|
17
|
+
from rich.panel import Panel
|
|
18
|
+
from rich.text import Text
|
|
19
|
+
from clirey.config import ClireyConfig, mask_broker_url
|
|
20
|
+
from clirey.core.client import CeleryClient
|
|
21
|
+
from clirey.core.events import EventMonitor
|
|
22
|
+
from clirey.mock.simulator import MockDashboard
|
|
23
|
+
from clirey.ui.console import console, err_console, format_event_badge
|
|
24
|
+
from clirey.ui.dashboard import Dashboard
|
|
25
|
+
from clirey.ui.tables import (
|
|
26
|
+
create_events_table,
|
|
27
|
+
create_queues_table,
|
|
28
|
+
create_tasks_table,
|
|
29
|
+
create_workers_table,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
app = typer.Typer(
|
|
33
|
+
name="clirey",
|
|
34
|
+
help="Clirey: Modern CLI & Live Terminal Monitor for Celery with just a Broker URL.",
|
|
35
|
+
add_completion=False,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def get_resolved_broker(broker: Optional[str]) -> str:
|
|
41
|
+
"""Resolve and validate broker URL."""
|
|
42
|
+
resolved = ClireyConfig.resolve_broker_url(broker)
|
|
43
|
+
if not resolved:
|
|
44
|
+
err_console.print(
|
|
45
|
+
"[bold red]Error:[/] No Celery broker URL specified!\n"
|
|
46
|
+
"Provide it via [bold yellow]--broker <url>[/] or set the [bold yellow]CELERY_BROKER_URL[/] environment variable."
|
|
47
|
+
)
|
|
48
|
+
raise typer.Exit(code=1)
|
|
49
|
+
return resolved
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@app.command(name="top")
|
|
53
|
+
@app.command(name="monitor")
|
|
54
|
+
@app.command(name="live")
|
|
55
|
+
def cmd_top(
|
|
56
|
+
broker: Optional[str] = typer.Option(
|
|
57
|
+
None,
|
|
58
|
+
"--broker",
|
|
59
|
+
"-b",
|
|
60
|
+
help="Celery broker URL (e.g., redis://localhost:6379/0 or amqp://guest:guest@localhost:5672//)",
|
|
61
|
+
),
|
|
62
|
+
backend: Optional[str] = typer.Option(
|
|
63
|
+
None,
|
|
64
|
+
"--backend",
|
|
65
|
+
help="Optional Celery result backend URL",
|
|
66
|
+
),
|
|
67
|
+
refresh: float = typer.Option(
|
|
68
|
+
1.5,
|
|
69
|
+
"--refresh",
|
|
70
|
+
"-r",
|
|
71
|
+
help="Dashboard refresh interval in seconds",
|
|
72
|
+
),
|
|
73
|
+
):
|
|
74
|
+
"""Launch the real-time interactive TUI dashboard."""
|
|
75
|
+
broker_url = get_resolved_broker(broker)
|
|
76
|
+
dashboard = Dashboard(broker_url=broker_url, backend_url=backend, refresh_rate=refresh)
|
|
77
|
+
dashboard.run()
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@app.command(name="demo")
|
|
81
|
+
def cmd_demo(
|
|
82
|
+
refresh: float = typer.Option(
|
|
83
|
+
1.0,
|
|
84
|
+
"--refresh",
|
|
85
|
+
"-r",
|
|
86
|
+
help="Demo refresh interval in seconds",
|
|
87
|
+
),
|
|
88
|
+
):
|
|
89
|
+
"""Run an interactive live demo simulator without needing a live Celery broker."""
|
|
90
|
+
demo = MockDashboard(refresh_rate=refresh)
|
|
91
|
+
demo.run()
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@app.command(name="workers")
|
|
95
|
+
@app.command(name="status")
|
|
96
|
+
def cmd_workers(
|
|
97
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
98
|
+
timeout: float = typer.Option(3.0, "--timeout", "-t", help="Timeout for worker inspection in seconds"),
|
|
99
|
+
):
|
|
100
|
+
"""List all connected Celery workers, pool concurrency, load, and stats."""
|
|
101
|
+
broker_url = get_resolved_broker(broker)
|
|
102
|
+
console.print(f"[dim]Connecting to broker: {mask_broker_url(broker_url)}[/]")
|
|
103
|
+
|
|
104
|
+
with console.status("[bold cyan]Inspecting Celery workers...[/]", spinner="dots"):
|
|
105
|
+
client = CeleryClient(broker_url=broker_url, timeout=timeout)
|
|
106
|
+
workers = client.get_workers()
|
|
107
|
+
|
|
108
|
+
if not workers:
|
|
109
|
+
console.print(
|
|
110
|
+
Panel(
|
|
111
|
+
"[bold yellow]No Celery workers responded within timeout.[/]\n\n"
|
|
112
|
+
"โข Check if workers are running and connected to this broker.\n"
|
|
113
|
+
"โข Verify that the broker URL is reachable.",
|
|
114
|
+
title="[bold red]No Workers Detected[/]",
|
|
115
|
+
border_style="red",
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
table = create_workers_table(workers)
|
|
121
|
+
console.print(table)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@app.command(name="tasks")
|
|
125
|
+
def cmd_tasks(
|
|
126
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
127
|
+
filter_type: str = typer.Option(
|
|
128
|
+
"all",
|
|
129
|
+
"--type",
|
|
130
|
+
"-t",
|
|
131
|
+
help="Task type to display: all, active, scheduled, reserved",
|
|
132
|
+
),
|
|
133
|
+
timeout: float = typer.Option(3.0, "--timeout", help="Timeout in seconds"),
|
|
134
|
+
):
|
|
135
|
+
"""List currently active, scheduled, or reserved tasks across the cluster."""
|
|
136
|
+
broker_url = get_resolved_broker(broker)
|
|
137
|
+
client = CeleryClient(broker_url=broker_url, timeout=timeout)
|
|
138
|
+
|
|
139
|
+
with console.status("[bold cyan]Fetching tasks from workers...[/]", spinner="dots"):
|
|
140
|
+
active = client.get_active_tasks() if filter_type in ("all", "active") else []
|
|
141
|
+
scheduled = client.get_scheduled_tasks() if filter_type in ("all", "scheduled") else []
|
|
142
|
+
reserved = client.get_reserved_tasks() if filter_type in ("all", "reserved") else []
|
|
143
|
+
|
|
144
|
+
all_tasks = active + scheduled + reserved
|
|
145
|
+
if not all_tasks:
|
|
146
|
+
console.print("[yellow]No tasks currently running or queued in workers.[/]")
|
|
147
|
+
return
|
|
148
|
+
|
|
149
|
+
table = create_tasks_table(all_tasks, title=f"Celery Tasks ({len(all_tasks)} found)")
|
|
150
|
+
console.print(table)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
@app.command(name="queues")
|
|
154
|
+
def cmd_queues(
|
|
155
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
156
|
+
timeout: float = typer.Option(3.0, "--timeout", help="Timeout in seconds"),
|
|
157
|
+
):
|
|
158
|
+
"""Inspect broker queue backlog depths and active worker subscriptions."""
|
|
159
|
+
broker_url = get_resolved_broker(broker)
|
|
160
|
+
client = CeleryClient(broker_url=broker_url, timeout=timeout)
|
|
161
|
+
|
|
162
|
+
with console.status("[bold cyan]Querying queues and broker backlog...[/]", spinner="dots"):
|
|
163
|
+
queues = client.get_queues()
|
|
164
|
+
|
|
165
|
+
table = create_queues_table(queues)
|
|
166
|
+
console.print(table)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
@app.command(name="events")
|
|
170
|
+
def cmd_events(
|
|
171
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
172
|
+
):
|
|
173
|
+
"""Stream real-time Celery events to standard output."""
|
|
174
|
+
broker_url = get_resolved_broker(broker)
|
|
175
|
+
console.print(f"[bold cyan]โก Streaming live Celery events from:[/] {mask_broker_url(broker_url)}")
|
|
176
|
+
console.print("[dim]Press Ctrl+C to stop streaming.\n[/]")
|
|
177
|
+
|
|
178
|
+
client = CeleryClient(broker_url=broker_url)
|
|
179
|
+
|
|
180
|
+
def on_event(ev):
|
|
181
|
+
t_str = time.strftime("%H:%M:%S", time.localtime(ev.timestamp))
|
|
182
|
+
task_name = ev.task_name or "unknown"
|
|
183
|
+
tid = f"[{ev.task_id[:8]}]" if ev.task_id else ""
|
|
184
|
+
dur = f"({ev.runtime:.2f}s)" if ev.runtime is not None else ""
|
|
185
|
+
worker = f"@{ev.worker}" if ev.worker else ""
|
|
186
|
+
badge = format_event_badge(ev.event_type)
|
|
187
|
+
|
|
188
|
+
console.print(f"[dim]{t_str}[/] {badge} [bold yellow]{task_name}[/] [dim]{tid}[/] [cyan]{worker}[/] [green]{dur}[/]")
|
|
189
|
+
if ev.exception:
|
|
190
|
+
console.print(f" [red]โโ Error: {ev.exception}[/]")
|
|
191
|
+
|
|
192
|
+
monitor = EventMonitor(client, on_event_callback=on_event)
|
|
193
|
+
monitor.start()
|
|
194
|
+
|
|
195
|
+
try:
|
|
196
|
+
while True:
|
|
197
|
+
time.sleep(0.5)
|
|
198
|
+
except KeyboardInterrupt:
|
|
199
|
+
monitor.stop()
|
|
200
|
+
console.print("\n[yellow]Stopped event stream.[/]")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
@app.command(name="ping")
|
|
204
|
+
def cmd_ping(
|
|
205
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
206
|
+
timeout: float = typer.Option(3.0, "--timeout", help="Timeout in seconds"),
|
|
207
|
+
):
|
|
208
|
+
"""Ping active Celery workers and check response latency."""
|
|
209
|
+
broker_url = get_resolved_broker(broker)
|
|
210
|
+
client = CeleryClient(broker_url=broker_url, timeout=timeout)
|
|
211
|
+
|
|
212
|
+
t0 = time.perf_counter()
|
|
213
|
+
with console.status("[bold cyan]Pinging workers...[/]", spinner="dots"):
|
|
214
|
+
res = client.ping()
|
|
215
|
+
elapsed_ms = (time.perf_counter() - t0) * 1000
|
|
216
|
+
|
|
217
|
+
if not res:
|
|
218
|
+
console.print("[bold red]โ No response from any worker.[/]")
|
|
219
|
+
raise typer.Exit(code=1)
|
|
220
|
+
|
|
221
|
+
console.print(f"[bold green]โ Received responses in {elapsed_ms:.1f}ms:[/]")
|
|
222
|
+
for worker, reply in res.items():
|
|
223
|
+
console.print(f" โข [bold cyan]{worker}:[/] [green]{reply}[/]")
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@app.command(name="task")
|
|
227
|
+
def cmd_task(
|
|
228
|
+
task_id: str = typer.Argument(..., help="Celery task UUID to inspect"),
|
|
229
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
230
|
+
backend: Optional[str] = typer.Option(None, "--backend", help="Optional result backend URL"),
|
|
231
|
+
):
|
|
232
|
+
"""Query a specific task across workers and result backend."""
|
|
233
|
+
broker_url = get_resolved_broker(broker)
|
|
234
|
+
client = CeleryClient(broker_url=broker_url, backend_url=backend)
|
|
235
|
+
|
|
236
|
+
with console.status(f"[bold cyan]Querying task {task_id}...[/]", spinner="dots"):
|
|
237
|
+
info = client.query_task(task_id)
|
|
238
|
+
|
|
239
|
+
console.print(Panel(str(info), title=f"Task Query: {task_id}", border_style="cyan"))
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@app.command(name="revoke")
|
|
243
|
+
def cmd_revoke(
|
|
244
|
+
task_id: str = typer.Argument(..., help="Celery task UUID to revoke"),
|
|
245
|
+
broker: Optional[str] = typer.Option(None, "--broker", "-b", help="Celery broker URL"),
|
|
246
|
+
terminate: bool = typer.Option(False, "--terminate", "-t", help="Terminate currently executing task process"),
|
|
247
|
+
signal: str = typer.Option("SIGTERM", "--signal", "-s", help="Signal to send when terminating (e.g. SIGTERM, SIGKILL)"),
|
|
248
|
+
):
|
|
249
|
+
"""Revoke or terminate a Celery task by ID."""
|
|
250
|
+
broker_url = get_resolved_broker(broker)
|
|
251
|
+
client = CeleryClient(broker_url=broker_url)
|
|
252
|
+
|
|
253
|
+
confirm = typer.confirm(f"Are you sure you want to revoke task '{task_id}' (terminate={terminate})?")
|
|
254
|
+
if not confirm:
|
|
255
|
+
console.print("[yellow]Aborted.[/]")
|
|
256
|
+
return
|
|
257
|
+
|
|
258
|
+
with console.status(f"[bold cyan]Revoking task {task_id}...[/]", spinner="dots"):
|
|
259
|
+
res = client.revoke_task(task_id, terminate=terminate, signal=signal)
|
|
260
|
+
|
|
261
|
+
console.print(f"[bold green]โ Revoke broadcast sent.[/] Replies: {res}")
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def main():
|
|
265
|
+
"""Main entrypoint for CLI execution."""
|
|
266
|
+
app()
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
if __name__ == "__main__":
|
|
270
|
+
main()
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Configuration and Broker URL resolution for Clirey."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Optional
|
|
9
|
+
from urllib.parse import urlparse, urlunparse
|
|
10
|
+
from pydantic import BaseModel, Field
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def mask_broker_url(url: str) -> str:
|
|
14
|
+
"""Mask password and sensitive credentials in broker URL for display."""
|
|
15
|
+
if not url:
|
|
16
|
+
return ""
|
|
17
|
+
try:
|
|
18
|
+
parsed = urlparse(url)
|
|
19
|
+
if parsed.password:
|
|
20
|
+
netloc = f"{parsed.username or ''}:****@{parsed.hostname or ''}"
|
|
21
|
+
if parsed.port:
|
|
22
|
+
netloc += f":{parsed.port}"
|
|
23
|
+
masked = parsed._replace(netloc=netloc)
|
|
24
|
+
return urlunparse(masked)
|
|
25
|
+
return url
|
|
26
|
+
except Exception:
|
|
27
|
+
# Fallback regex mask
|
|
28
|
+
return re.sub(r":([^@]+)@", r":****@", url)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ClireyConfig(BaseModel):
|
|
32
|
+
"""Clirey configuration settings."""
|
|
33
|
+
broker_url: str = Field(default="redis://localhost:6379/0", description="Celery broker connection URL")
|
|
34
|
+
result_backend: Optional[str] = Field(default=None, description="Optional Celery result backend URL")
|
|
35
|
+
refresh_rate: float = Field(default=1.5, description="Dashboard refresh rate in seconds")
|
|
36
|
+
timeout: float = Field(default=2.5, description="Timeout for inspect / ping requests")
|
|
37
|
+
event_buffer_size: int = Field(default=1000, description="Max event log buffer size")
|
|
38
|
+
max_history_tasks: int = Field(default=500, description="Max task history records")
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def resolve_broker_url(cls, explicit_url: Optional[str] = None) -> str:
|
|
42
|
+
"""Resolve broker URL by checking:
|
|
43
|
+
1. Explicitly passed parameter
|
|
44
|
+
2. Environment variables: CELERY_BROKER_URL, CLIREY_BROKER_URL, REDIS_URL, RABBITMQ_URL, AMQP_URL
|
|
45
|
+
3. Config file in current directory or user home
|
|
46
|
+
4. Default localhost redis
|
|
47
|
+
"""
|
|
48
|
+
if explicit_url and explicit_url.strip():
|
|
49
|
+
return explicit_url.strip()
|
|
50
|
+
|
|
51
|
+
env_keys = [
|
|
52
|
+
"CLIREY_BROKER_URL",
|
|
53
|
+
"CELERY_BROKER_URL",
|
|
54
|
+
"REDIS_URL",
|
|
55
|
+
"RABBITMQ_URL",
|
|
56
|
+
"AMQP_URL",
|
|
57
|
+
]
|
|
58
|
+
for key in env_keys:
|
|
59
|
+
val = os.environ.get(key)
|
|
60
|
+
if val and val.strip():
|
|
61
|
+
return val.strip()
|
|
62
|
+
|
|
63
|
+
# Check for config files (.clirey.json or ~/.clirey.json)
|
|
64
|
+
local_cfg = Path(".clirey.json")
|
|
65
|
+
home_cfg = Path.home() / ".clirey.json"
|
|
66
|
+
for p in [local_cfg, home_cfg]:
|
|
67
|
+
if p.exists() and p.is_file():
|
|
68
|
+
try:
|
|
69
|
+
import json
|
|
70
|
+
data = json.loads(p.read_text(encoding="utf-8"))
|
|
71
|
+
if "broker_url" in data and data["broker_url"]:
|
|
72
|
+
return str(data["broker_url"]).strip()
|
|
73
|
+
except Exception:
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
return "redis://localhost:6379/0"
|