This directory contains practical examples demonstrating Queuack's features from basic to advanced use cases.
# Install Queuack
pip install queuack
# Run a basic example
python 01_basic/simple_queue.py
# Start a worker
python 02_workers/single_worker.pyLearn the fundamentals: enqueue, claim, ack, priorities, delays, and batch operations.
Start here if you're new to Queuack.
simple_queue.py- Basic producer/consumer patternpriority_jobs.py- Priority-based job orderingdelayed_jobs.py- Schedule jobs for future executionbatch_enqueue.py- Efficiently enqueue multiple jobs
Understand how to build robust worker processes with concurrency, multi-queue support, and graceful shutdown.
single_worker.py- Basic long-running workerconcurrent_workers.py- Multi-threaded parallel executionmulti_queue_worker.py- Process multiple queues with prioritiesgraceful_shutdown.py- Handle signals properly
Master complex workflows with dependencies, parallel execution, and conditional logic.
linear_pipeline.py- Simple A → B → C pipelinefan_out_fan_in.py- Parallel processing with synchronizationconditional_execution.py- OR-based dependencies (ANY mode)diamond_dependency.py- Diamond pattern synchronizationexternal_dependencies.py- Reference external jobs
Advanced techniques for production deployments and monitoring.
01_custom_backpressure.py- Custom backpressure thresholds and adaptive policies02_monitoring_dashboard.py- Real-time web monitoring dashboard (Chart.js, WebSocket)03_distributed_workers.py- Multi-machine worker deployment04_run_strategies.py- Advanced retry and backoff strategies05_dag_visualization.py- Generate DAG diagrams (Mermaid)06_custom_colors.py- Custom Mermaid color schemes (6 themes)
Production-ready patterns organized by domain:
01_etl/- ETL & Data Pipelines (streaming, Spark, multi-format)02_web/- Web scraping, async APIs, image processing03_ml/- ML pipelines, hyperparameter tuning, experiment tracking04_integration/- Framework integration (Flask, FastAPI, Django, CLI)
See each subfolder for detailed examples and README.
cd 01_basic
python simple_queue.py# Terminal 1: Enqueue jobs
python -c "
from queuack import DuckQueue
queue = DuckQueue('test.db')
for i in range(10):
queue.enqueue(lambda x: print(x), args=(i,))
"
# Terminal 2: Run worker
cd 02_workers
python single_worker.pycd 03_dag_workflows
python linear_pipeline.py
# Then start worker to process the DAG
python ../02_workers/single_worker.pycd 05_real_world/01_etl
python streaming_etl.py
# Monitor progress (optional)
cd ../../04_advanced
python 02_monitoring_dashboard.pyFunctions must be module-level (not lambdas or nested):
# ✓ Good
def process_data(x):
return x * 2
queue.enqueue(process_data, args=(5,))
# ✗ Bad
queue.enqueue(lambda x: x * 2, args=(5,)) # Won't pickle!Always set appropriate max_attempts and timeout_seconds:
queue.enqueue(
flaky_api_call,
max_attempts=5, # Retry up to 5 times
timeout_seconds=300 # 5 minute timeout
)Use check_backpressure=True for producer throttling:
try:
queue.enqueue(task, check_backpressure=True)
except BackpressureError:
# Queue is full, slow down!
time.sleep(10)Use named nodes for readability:
with queue.dag("pipeline") as dag:
extract = dag.enqueue(extract_func, name="extract")
transform = dag.enqueue(
transform_func,
name="transform",
depends_on="extract" # Use name, not job ID
)Match concurrency to workload:
# CPU-bound tasks: concurrency = CPU cores
Worker(queue, concurrency=4)
# I/O-bound tasks: concurrency = 10-50
Worker(queue, concurrency=20)# Machine 1: Run worker
python -m queuack.worker --db=/shared/queue.db --concurrency=8
# Machine 2: Run worker
python -m queuack.worker --db=/shared/queue.db --concurrency=8
# Machine 3: Enqueue jobs
python producer.pyFROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
# Run worker
CMD ["python", "-m", "queuack.worker", "--db=/data/queue.db"]# Use CLI tool
pip install queuack[cli]
# Check stats
queuack --db queue.db stats
# Monitor DAG
queuack --db queue.db dag-status
# Start worker
queuack --db queue.db worker --concurrency=4All examples include inline tests. Run with pytest:
pytest 01_basic/
pytest 03_dag_workflows/
pytest --verbose # Detailed output- Batch Operations: Use
enqueue_batch()for bulk inserts - Connection Pooling: One DB file per queue for hot paths
- Purge Old Jobs: Run
queue.purge()regularly - Index Optimization: Default indexes are sufficient for most cases
- Worker Placement: Colocate workers with data sources
- Worker crashed without releasing claim
- Wait for claim timeout (default: 300s) or restart worker
- Purge completed jobs regularly
- Reduce worker concurrency
- Process large data in chunks
- Check database file location (SSD vs HDD)
- Reduce job count via purging
- Split into multiple queues
Have a useful example? Submit a PR:
- Add to appropriate directory
- Include docstring and inline comments
- Add entry to this README
- Ensure code is self-contained and runnable
- Documentation: https://queuack.readthedocs.io
- Issues: https://github.com/queuack/queuack/issues
- Discussions: https://github.com/queuack/queuack/discussions
All examples are MIT licensed - use them freely in your projects.