CLI Commands
bunqueue includes a powerful CLI for server management and job operations. The CLI works in two modes:
- Server mode: Start the bunqueue server
- Client mode: Send commands to a running server
Getting Started
Start the Server
# Start with defaults (TCP: 6789, HTTP: 6790)bunqueue start
# Custom portsbunqueue start --tcp-port 7000 --http-port 7001
# With persistent storagebunqueue start --data-path ./data/production.db
# With authenticationAUTH_TOKENS=secret-token bunqueue startOutput:
bunqueue v1.6.0TCP server listening on port 6789HTTP server listening on port 6790Database: ./data/bunq.dbConnect to Server
All client commands connect to a running server:
# Default connection (localhost:6789)bunqueue stats
# Connect to remote serverbunqueue stats --host 192.168.1.100 --port 6789
# With authenticationbunqueue stats --token secret-tokenCore Operations
Push Jobs
Add jobs to a queue for processing.
# Basic pushbunqueue push emails '{"to":"user@example.com","subject":"Welcome"}'Output:
Job pushed successfullyID: 1001Queue: emailsPriority: 0# With priority (higher = processed first)bunqueue push emails '{"to":"vip@example.com"}' --priority 10Output:
Job pushed successfullyID: 1002Queue: emailsPriority: 10# Delayed job (process after 5 seconds)bunqueue push notifications '{"message":"Reminder"}' --delay 5000Output:
Job pushed successfullyID: 1003Queue: notificationsState: delayedRun at: 2024-01-15T10:30:05.000Z# With custom job IDbunqueue push orders '{"orderId":"ORD-123"}' --job-id order-ORD-123Pull Jobs
Retrieve jobs for processing (typically used by workers).
# Pull next jobbunqueue pull emailsOutput:
{ "id": "1001", "name": "default", "data": {"to":"user@example.com","subject":"Welcome"}, "priority": 0, "attempts": 0, "timestamp": 1704067200000}# Pull with timeout (wait up to 5s for job)bunqueue pull emails --timeout 5000# Pull returns null if queue is emptybunqueue pull empty-queueOutput:
No jobs availableAcknowledge Jobs
Mark jobs as completed after successful processing.
# Simple acknowledgmentbunqueue ack 1001Output:
Job 1001 acknowledgedState: completed# With result databunqueue ack 1001 --result '{"messageId":"msg-abc123","delivered":true}'Output:
Job 1001 acknowledgedState: completedResult: {"messageId":"msg-abc123","delivered":true}Fail Jobs
Mark jobs as failed (will retry if attempts remaining).
# Mark as failedbunqueue fail 1001 --error "SMTP connection timeout"Output:
Job 1001 marked as failedError: SMTP connection timeoutAttempts: 1/3Next retry: 2024-01-15T10:31:00.000Z# Job moved to DLQ after max attemptsbunqueue fail 1001 --error "Permanent failure"Output:
Job 1001 marked as failedError: Permanent failureAttempts: 3/3Status: Moved to DLQJob Management
Get Job Information
# Full job detailsbunqueue job get 1001Output:
{ "id": "1001", "name": "send-email", "queue": "emails", "data": {"to":"user@example.com"}, "state": "completed", "priority": 0, "attempts": 1, "progress": 100, "timestamp": 1704067200000, "processedOn": 1704067201000, "finishedOn": 1704067202000, "returnvalue": {"sent":true}}# Just the statebunqueue job state 1001Output:
completed# Get the resultbunqueue job result 1001Output:
{"sent":true,"messageId":"msg-abc123"}Control Jobs
# Cancel a waiting/delayed jobbunqueue job cancel 1002Output:
Job 1002 cancelledPrevious state: delayed# Promote delayed job to waiting (process immediately)bunqueue job promote 1003Output:
Job 1003 promotedPrevious state: delayedNew state: waiting# Discard a job completelybunqueue job discard 1004Output:
Job 1004 discardedUpdate Job Properties
# Update progress (0-100)bunqueue job progress 1001 50 --message "Processing attachments"Output:
Job 1001 progress updatedProgress: 50%Message: Processing attachments# Change prioritybunqueue job priority 1001 20Output:
Job 1001 priority updatedNew priority: 20# Add delay to existing jobbunqueue job delay 1001 60000Output:
Job 1001 delayedRun at: 2024-01-15T10:31:00.000ZJob Logs
# View job logsbunqueue job logs 1001Output:
[2024-01-15 10:30:00] INFO Starting email processing[2024-01-15 10:30:01] INFO Template loaded: welcome[2024-01-15 10:30:02] INFO Email sent successfully# Add log entrybunqueue job log 1001 "Custom checkpoint reached" --level infoOutput:
Log entry added to job 1001Queue Control
List Queues
bunqueue queue listOutput:
QUEUE WAITING ACTIVE COMPLETED FAILED PAUSEDemails 125 5 10,234 23 nonotifications 50 2 5,102 5 noreports 0 1 892 0 yesPause and Resume
# Pause processing (workers won't pick new jobs)bunqueue queue pause emailsOutput:
Queue 'emails' pausedWaiting jobs: 125 (will not be processed)Active jobs: 5 (will complete)# Resume processingbunqueue queue resume emailsOutput:
Queue 'emails' resumedProcessing will continueView Queue Jobs
# List waiting jobsbunqueue queue jobs emails --state waiting --limit 10Output:
ID NAME PRIORITY CREATED1001 send-email 10 2024-01-15 10:30:001002 send-email 5 2024-01-15 10:30:011003 send-email 0 2024-01-15 10:30:02...Showing 10 of 125 jobs# List failed jobsbunqueue queue jobs emails --state failedClean Old Jobs
# Remove completed jobs older than 1 hourbunqueue queue clean emails --grace 3600000 --state completedOutput:
Cleaned 1,523 jobs from 'emails'State: completedOlder than: 1 hour# Clean all old jobs (completed and failed)bunqueue queue clean emails --grace 86400000Drain and Obliterate
# Remove all waiting jobs (keep active)bunqueue queue drain emailsOutput:
Queue 'emails' drainedRemoved: 125 waiting jobsActive jobs: 5 (still processing)# Remove everything (dangerous!)bunqueue queue obliterate emailsOutput:
⚠️ This will remove ALL data for queue 'emails'Type 'emails' to confirm: emailsQueue 'emails' obliteratedRemoved: 125 waiting, 5 active, 10,234 completed, 23 failedDLQ Operations
View Dead Letter Queue
bunqueue dlq list emailsOutput:
ID JOB_ID ERROR FAILED_AT ATTEMPTS1 1001 SMTP timeout 2024-01-15 10:30:00 32 1005 Invalid recipient 2024-01-15 10:31:00 33 1008 Rate limit exceeded 2024-01-15 10:32:00 3
Total: 3 entriesRetry DLQ Jobs
# Retry all DLQ jobsbunqueue dlq retry emailsOutput:
Retrying 3 jobs from DLQJobs moved back to 'emails' queue# Retry specific jobbunqueue dlq retry emails --id 1001Output:
Job 1001 moved from DLQ to 'emails' queuePurge DLQ
bunqueue dlq purge emailsOutput:
⚠️ This will permanently delete all DLQ entries for 'emails'Type 'purge' to confirm: purgePurged 3 entries from DLQCron Jobs
List Scheduled Jobs
bunqueue cron listOutput:
NAME QUEUE SCHEDULE NEXT RUN EXECUTIONSdaily-report reports 0 6 * * * 2024-01-16 06:00:00 45hourly-cleanup cleanup 0 * * * * 2024-01-15 11:00:00 1,082health-check health */5 * * * * 2024-01-15 10:35:00 8,640Add Cron Job
# Using cron expression (daily at 6 AM)bunqueue cron add daily-report \ -q reports \ -d '{"type":"daily","format":"pdf"}' \ -s "0 6 * * *"Output:
Cron job 'daily-report' createdQueue: reportsSchedule: 0 6 * * * (daily at 6:00 AM)Next run: 2024-01-16 06:00:00# Using interval (every 30 minutes)bunqueue cron add health-check \ -q health \ -d '{"check":"all"}' \ -e 1800000Output:
Cron job 'health-check' createdQueue: healthInterval: every 30 minutesNext run: 2024-01-15 11:00:00Delete Cron Job
bunqueue cron delete daily-reportOutput:
Cron job 'daily-report' deletedRate Limiting
Set Rate Limit
# Limit to 100 jobs per secondbunqueue rate-limit set emails 100Output:
Rate limit set for 'emails'Limit: 100 jobs/secondSet Concurrency Limit
# Max 10 concurrent jobsbunqueue concurrency set emails 10Output:
Concurrency limit set for 'emails'Limit: 10 concurrent jobsClear Limits
bunqueue rate-limit clear emailsbunqueue concurrency clear emailsOutput:
Rate limit cleared for 'emails'Concurrency limit cleared for 'emails'Monitoring
Server Stats
bunqueue statsOutput:
bunqueue Server Statistics==========================Uptime: 2d 5h 30mVersion: 1.6.0
Queues: 5Total Jobs: 156,234 - Waiting: 234 - Active: 12 - Completed: 155,800 - Failed: 188
Database Size: 45.2 MBWAL Size: 2.1 MBPrometheus Metrics
bunqueue metricsOutput:
# HELP bunqueue_jobs_total Total number of jobs# TYPE bunqueue_jobs_total counterbunqueue_jobs_total{queue="emails",state="completed"} 155800bunqueue_jobs_total{queue="emails",state="failed"} 188
# HELP bunqueue_job_duration_seconds Job processing duration# TYPE bunqueue_job_duration_seconds histogrambunqueue_job_duration_seconds_bucket{queue="emails",le="0.1"} 145000bunqueue_job_duration_seconds_bucket{queue="emails",le="1"} 155000...Health Check
bunqueue healthOutput:
{ "status": "healthy", "uptime": 185400, "version": "1.6.0", "database": { "status": "ok", "size": 47409152, "wal_size": 2202880 }, "queues": 5, "jobs": { "active": 12, "waiting": 234 }}Backup Operations
Create Backup
bunqueue backup nowOutput:
Backup started...Uploading to S3: backups/2024-01-15/bunq-103000.dbBackup completed successfullySize: 45.2 MBDuration: 2.3sList Backups
bunqueue backup listOutput:
KEY SIZE CREATEDbackups/2024-01-15/bunq-103000.db 45.2 MB 2024-01-15 10:30:00backups/2024-01-14/bunq-103000.db 44.8 MB 2024-01-14 10:30:00backups/2024-01-13/bunq-103000.db 43.2 MB 2024-01-13 10:30:00Restore Backup
bunqueue backup restore backups/2024-01-14/bunq-103000.dbOutput:
⚠️ This will overwrite the current databaseType 'restore' to confirm: restoreDownloading backup...Restoring database...Restore completed successfullyBackup Status
bunqueue backup statusOutput:
S3 Backup Configuration=======================Enabled: trueBucket: my-backupsRegion: us-east-1Interval: 6 hoursRetention: 7 backupsLast backup: 2024-01-15 10:30:00Next backup: 2024-01-15 16:30:00Global Options
| Option | Short | Description | Default |
|---|---|---|---|
--host | -H | Server hostname | localhost |
--port | -p | TCP port | 6789 |
--token | -t | Authentication token | - |
--json | - | Output as JSON | false |
--help | -h | Show help | - |
--version | -v | Show version | - |
JSON Output
All commands support JSON output for scripting:
bunqueue stats --json | jq '.jobs.waiting'Output:
234# Use in scriptsWAITING=$(bunqueue queue jobs emails --state waiting --json | jq 'length')if [ "$WAITING" -gt 1000 ]; then echo "Warning: Queue backlog detected"fiCommon Workflows
Process Jobs Manually
# 1. Pull a jobJOB=$(bunqueue pull emails --json)JOB_ID=$(echo $JOB | jq -r '.id')
# 2. Process it (your logic here)echo "Processing job $JOB_ID..."
# 3. Acknowledge or failbunqueue ack $JOB_ID --result '{"processed":true}'Monitor Queue Health
#!/bin/bash# monitor.sh - Alert if queue backlog grows
THRESHOLD=1000WAITING=$(bunqueue queue jobs emails --state waiting --json | jq 'length')
if [ "$WAITING" -gt "$THRESHOLD" ]; then echo "ALERT: emails queue has $WAITING waiting jobs" # Send notification...fiScheduled Maintenance
#!/bin/bash# maintenance.sh - Daily cleanup
# Clean old completed jobs (older than 24h)bunqueue queue clean emails --grace 86400000 --state completedbunqueue queue clean notifications --grace 86400000 --state completed
# Purge old DLQ entriesbunqueue dlq purge emails
# Create backupbunqueue backup now