celers-cli 0.1.0

Command-line interface for CeleRS worker and queue management
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
# celers-cli

Command-line interface for managing CeleRS workers, queues, and task execution.

## Overview

**Status: ✅ FEATURE COMPLETE**

A comprehensive CLI tool providing full-featured management for CeleRS distributed task queues. Supports multiple brokers (Redis, PostgreSQL), advanced worker management, monitoring, debugging, and operational workflows.

## Installation

```bash
# Install from source
cargo install --path crates/celers-cli

# The binary is named 'celers'
celers --help
```

## Quick Start

```bash
# Initialize configuration
celers init

# Start a worker
celers worker --broker redis://localhost:6379 --queue my_queue --concurrency 4

# Check queue status
celers status --broker redis://localhost:6379 --queue my_queue

# Run health diagnostics
celers health --broker redis://localhost:6379

# Launch interactive dashboard
celers dashboard --broker redis://localhost:6379 --queue my_queue
```

## Core Features

### Worker Management

```bash
# Start worker with configuration
celers worker --broker redis://localhost:6379 --queue my_queue --concurrency 8

# List all running workers
celers worker-mgmt list --broker redis://localhost:6379

# Show worker statistics
celers worker-mgmt stats <worker-id> --broker redis://localhost:6379

# Stop a worker (graceful)
celers worker-mgmt stop <worker-id> --graceful --broker redis://localhost:6379

# Pause/resume worker
celers worker-mgmt pause <worker-id> --broker redis://localhost:6379
celers worker-mgmt resume <worker-id> --broker redis://localhost:6379

# Drain worker (finish current tasks, accept no new ones)
celers worker-mgmt drain <worker-id> --broker redis://localhost:6379

# Stream worker logs
celers worker-mgmt logs <worker-id> --follow --level info --broker redis://localhost:6379

# Scale workers
celers worker-mgmt scale 5 --broker redis://localhost:6379
```

### Queue Management

```bash
# List all queues (Redis)
celers queue list --broker redis://localhost:6379

# Show detailed queue statistics
celers queue stats --queue my_queue --broker redis://localhost:6379

# Pause/resume queue processing
celers queue pause --queue my_queue --broker redis://localhost:6379
celers queue resume --queue my_queue --broker redis://localhost:6379

# Purge all tasks from queue
celers queue purge --queue my_queue --confirm --broker redis://localhost:6379

# Move tasks between queues
celers queue move --from old_queue --to new_queue --confirm --broker redis://localhost:6379

# Export/import queues
celers queue export --queue my_queue --output backup.json --broker redis://localhost:6379
celers queue import --queue my_queue --input backup.json --confirm --broker redis://localhost:6379
```

### Task Operations

```bash
# Inspect task details
celers task inspect <task-id> --broker redis://localhost:6379 --queue my_queue

# Cancel a running task
celers task cancel <task-id> --broker redis://localhost:6379 --queue my_queue

# Retry a failed task
celers task retry <task-id> --broker redis://localhost:6379 --queue my_queue

# Show task result
celers task result <task-id> --backend redis://localhost:6379

# Show task execution logs
celers task logs <task-id> --broker redis://localhost:6379 --limit 100

# Move task to different queue
celers task requeue <task-id> --from queue1 --to queue2 --broker redis://localhost:6379
```

### Dead Letter Queue (DLQ)

```bash
# Inspect failed tasks
celers dlq inspect --broker redis://localhost:6379 --queue my_queue --limit 20

# Clear all DLQ tasks
celers dlq clear --confirm --broker redis://localhost:6379 --queue my_queue

# Replay specific task from DLQ
celers dlq replay <task-id> --broker redis://localhost:6379 --queue my_queue
```

### Scheduling & Beat

```bash
# List scheduled tasks
celers schedule list --broker redis://localhost:6379

# Add new scheduled task
celers schedule add my_daily_task \
  --task process_data \
  --cron "0 0 * * *" \
  --queue my_queue \
  --args '{"param": "value"}' \
  --broker redis://localhost:6379

# Pause/resume schedule
celers schedule pause my_daily_task --broker redis://localhost:6379
celers schedule resume my_daily_task --broker redis://localhost:6379

# Manually trigger scheduled task
celers schedule trigger my_daily_task --broker redis://localhost:6379

# Show execution history
celers schedule history my_daily_task --limit 50 --broker redis://localhost:6379

# Remove schedule
celers schedule remove my_daily_task --confirm --broker redis://localhost:6379
```

### Monitoring & Metrics

```bash
# Display live metrics
celers metrics --format text

# Export metrics to file
celers metrics --format json --output metrics.json
celers metrics --format prometheus --output metrics.prom

# Filter metrics by pattern
celers metrics --pattern "task_*" --format text

# Watch mode (auto-refresh)
celers metrics --watch 5  # Refresh every 5 seconds

# Interactive dashboard (TUI)
celers dashboard --broker redis://localhost:6379 --queue my_queue --refresh 1
```

### Auto-scaling

```bash
# Start auto-scaling service
celers autoscale start --broker redis://localhost:6379 --queue my_queue

# Check auto-scaling status
celers autoscale status --broker redis://localhost:6379
```

### Alerting

```bash
# Start alert monitoring
celers alert start --broker redis://localhost:6379 --queue my_queue

# Test webhook notification
celers alert test --webhook-url https://hooks.example.com/alerts --message "Test alert"
```

### Debugging & Diagnostics

```bash
# Debug task execution
celers debug task <task-id> --broker redis://localhost:6379 --queue my_queue

# Debug worker issues
celers debug worker <worker-id> --broker redis://localhost:6379

# System health check
celers health --broker redis://localhost:6379 --queue my_queue

# Automatic problem detection
celers doctor --broker redis://localhost:6379 --queue my_queue
```

### Reporting & Analytics

```bash
# Daily execution report
celers report daily --broker redis://localhost:6379 --queue my_queue

# Weekly statistics
celers report weekly --broker redis://localhost:6379 --queue my_queue

# Analyze performance bottlenecks
celers analyze bottlenecks --broker redis://localhost:6379 --queue my_queue

# Analyze failure patterns
celers analyze failures --broker redis://localhost:6379 --queue my_queue
```

### Database Operations

```bash
# Test database connection
celers db test-connection --url postgresql://user:pass@localhost/celers

# Run latency benchmark
celers db test-connection --url postgresql://user:pass@localhost/celers --benchmark

# Check database health
celers db health --url postgresql://user:pass@localhost/celers

# Show connection pool statistics
celers db pool-stats --url postgresql://user:pass@localhost/celers

# Apply migrations
celers db migrate --url postgresql://user:pass@localhost/celers --action apply

# Check migration status
celers db migrate --url postgresql://user:pass@localhost/celers --action status
```

## Configuration

### Generate Default Configuration

```bash
celers init --output celers.toml
```

### Configuration File Format

```toml
# celers.toml

[broker]
type = "redis"  # or "postgres"
url = "redis://localhost:6379"
queue = "celers"
mode = "fifo"  # or "priority"

# Broker failover (optional)
failover_urls = [
    "redis://backup1:6379",
    "redis://backup2:6379"
]
failover_retry_attempts = 3
failover_timeout_secs = 5

[worker]
concurrency = 4
poll_interval_ms = 1000
max_retries = 3
default_timeout_secs = 300

# Multiple queues
queues = ["celers", "high_priority", "low_priority"]

[autoscale]
enabled = false
min_workers = 1
max_workers = 10
scale_up_threshold = 80
scale_down_threshold = 20
check_interval_secs = 60

[alerts]
enabled = false
webhook_url = "https://hooks.example.com/alerts"
check_interval_secs = 60
dlq_threshold = 100
failed_tasks_threshold = 50
```

### Environment Variables

Configuration supports environment variable expansion:

```toml
[broker]
url = "${REDIS_URL:redis://localhost:6379}"  # Uses $REDIS_URL or default
queue = "${QUEUE_NAME}"  # Uses $QUEUE_NAME
```

### Profile Support

Use different configurations for different environments:

```bash
# Create profile-specific configs
celers init --output celers-dev.toml
celers init --output celers-prod.toml

# Use specific profile
celers worker --config celers-prod.toml
```

### Configuration Validation

```bash
# Validate configuration file
celers validate --config celers.toml

# Validate and test broker connection
celers validate --config celers.toml --test-connection
```

## Shell Completion

Generate completion scripts for your shell:

```bash
# Bash
celers completions bash > /etc/bash_completion.d/celers

# Zsh
celers completions zsh > /usr/share/zsh/site-functions/_celers

# Fish
celers completions fish > ~/.config/fish/completions/celers.fish

# PowerShell
celers completions powershell > celers.ps1

# Elvish
celers completions elvish > celers.elv
```

## Man Pages

Generate and install man pages:

```bash
# Generate man pages
celers manpages --output ./man

# Install system-wide
sudo cp ./man/celers.1 /usr/share/man/man1/
sudo mandb

# View man page
man celers
```

## Broker Support

### Redis

Full support for all features:
- FIFO and Priority queues
- Real-time monitoring
- Pub/Sub for commands
- DLQ management
- Task scheduling

```bash
celers worker --broker redis://localhost:6379 --queue my_queue
```

### PostgreSQL

Full support for all features:
- FIFO and Priority queues
- Transaction support
- Schema migrations
- Connection pooling

```bash
celers worker --broker postgresql://user:pass@localhost/celers --queue my_queue
```

## Advanced Usage

### Multi-Queue Management

```bash
# Configure multiple queues in config file
[worker]
queues = ["high", "medium", "low"]

# Start worker processing all queues
celers worker --config celers.toml
```

### Production Workflows

```bash
# 1. Health check before deployment
celers doctor --broker redis://prod:6379 --queue production

# 2. Drain workers for maintenance
celers worker-mgmt drain <worker-id> --broker redis://prod:6379

# 3. Export queue for backup
celers queue export --queue production --output backup-$(date +%Y%m%d).json

# 4. Monitor with auto-refresh
celers metrics --watch 10 --format text

# 5. Set up alerting
celers alert start --broker redis://prod:6379 --queue production
```

### Automation & Scripting

The CLI returns appropriate exit codes for scripting:

```bash
#!/bin/bash
# Check if queue is healthy
if celers health --broker redis://localhost:6379 --queue my_queue; then
    echo "Queue is healthy"
else
    echo "Queue has issues"
    celers doctor --broker redis://localhost:6379 --queue my_queue
fi
```

## Command Reference

| Category | Command | Description |
|----------|---------|-------------|
| **Worker** | `worker` | Start worker process |
| | `worker-mgmt list` | List all workers |
| | `worker-mgmt stats` | Worker statistics |
| | `worker-mgmt stop` | Stop worker |
| | `worker-mgmt pause/resume` | Pause/resume worker |
| | `worker-mgmt drain` | Drain worker |
| | `worker-mgmt scale` | Scale workers |
| | `worker-mgmt logs` | Stream worker logs |
| **Queue** | `queue list` | List queues |
| | `queue stats` | Queue statistics |
| | `queue purge` | Clear queue |
| | `queue move` | Move tasks |
| | `queue export/import` | Backup/restore |
| | `queue pause/resume` | Pause/resume queue |
| **Task** | `task inspect` | Task details |
| | `task cancel` | Cancel task |
| | `task retry` | Retry task |
| | `task result` | Show result |
| | `task logs` | Task logs |
| | `task requeue` | Move task |
| **DLQ** | `dlq inspect` | View failed tasks |
| | `dlq clear` | Clear DLQ |
| | `dlq replay` | Retry task |
| **Schedule** | `schedule list` | List schedules |
| | `schedule add` | Add schedule |
| | `schedule remove` | Remove schedule |
| | `schedule pause/resume` | Pause/resume |
| | `schedule trigger` | Manual trigger |
| | `schedule history` | Execution history |
| **Monitoring** | `metrics` | Show metrics |
| | `dashboard` | Interactive TUI |
| | `autoscale start/status` | Auto-scaling |
| | `alert start/test` | Alerting |
| **Diagnostics** | `health` | Health check |
| | `doctor` | Problem detection |
| | `debug task/worker` | Debug tools |
| **Reporting** | `report daily/weekly` | Reports |
| | `analyze bottlenecks` | Performance |
| | `analyze failures` | Failure patterns |
| **Database** | `db test-connection` | Test connection |
| | `db health` | Database health |
| | `db pool-stats` | Pool statistics |
| | `db migrate` | Run migrations |
| **Config** | `init` | Generate config |
| | `validate` | Validate config |
| | `completions` | Shell completion |
| | `manpages` | Generate man pages |
| **Other** | `status` | Queue status |

## Colored Output

The CLI uses colored output for better readability:
- 🟢 Green: Success messages
- 🟡 Yellow: Warnings
- 🔴 Red: Errors
- 🔵 Cyan: Information

Colors are automatically disabled when output is piped or in CI environments.

## Exit Codes

- `0`: Success
- `1`: General error
- `2`: Configuration error
- `3`: Connection error

## Contributing

See the main CeleRS repository for contribution guidelines.

## See Also

- `celers-core`: Core types and traits
- `celers-worker`: Worker runtime
- `celers-broker-redis`: Redis broker implementation
- `celers-broker-postgres`: PostgreSQL broker implementation
- `celers-metrics`: Metrics collection and export

## License

See LICENSE file in the repository root.