Quick Start
Get TaskDaemon running in under 5 minutes.
Prerequisites
Docker installed and running
Steps
Create a Handler
Create a new directory and add a simple Python handler:mkdir taskdaemon-quickstart && cd taskdaemon-quickstart
Create handler.py:import json
import sys
for line in sys.stdin:
task = json.loads(line)
name = task["task_data"].get("name", "World")
result = {"message": f"Hello, {name}!"}
print(json.dumps({"status": "success", "result": result}), flush=True)
Create Dockerfile.handler:FROM python:3.11-slim
COPY handler.py /app/
WORKDIR /app
CMD ["python", "-u", "handler.py"]
Build the Handler Image
docker build -f Dockerfile.handler -t my-greeter:latest .
Create Handler Config
Create handlers.toml:[handlers.greet]
image = "my-greeter:latest"
instances = 2
handler_selection = "round-robin"
Start TaskDaemon
docker run -d --name taskdaemon \
-p 8080:8080 \
-v $(pwd)/handlers.toml:/app/handlers.toml \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DAEMON_QUEUE_TYPE=hybrid \
mshelia/taskdaemon
Wait a few seconds, then check logs:You should see:INFO task_daemon: TaskDaemon started http_port=8080 grpc_port=50051 workers=2
Queue a Task
curl -X POST http://localhost:8080/queue \
-H "Content-Type: application/json" \
-d '{"type": "greet", "data": {"name": "TaskDaemon"}}'
Response:{"task_id":"550e8400-e29b-41d4-a716-446655440000"}
Check Result
curl http://localhost:8080/api/tasks/<task_id>
Response:{
"id": "550e8400-e29b-41d4-a716-446655440000",
"status": "completed",
"result": {"message": "Hello, TaskDaemon!"}
}
Cleanup
docker stop taskdaemon && docker rm taskdaemon
Complete Script
Here’s everything in one script:
#!/bin/bash
set -e
# Create handler
cat > handler.py << 'EOF'
import json
import sys
for line in sys.stdin:
task = json.loads(line)
name = task["task_data"].get("name", "World")
result = {"message": f"Hello, {name}!"}
print(json.dumps({"status": "success", "result": result}), flush=True)
EOF
# Create Dockerfile
cat > Dockerfile.handler << 'EOF'
FROM python:3.11-slim
COPY handler.py /app/
WORKDIR /app
CMD ["python", "-u", "handler.py"]
EOF
# Create config
cat > handlers.toml << 'EOF'
[handlers.greet]
image = "my-greeter:latest"
instances = 2
handler_selection = "round-robin"
EOF
# Build handler
docker build -f Dockerfile.handler -t my-greeter:latest .
# Start TaskDaemon
docker run -d --name taskdaemon \
-p 8080:8080 \
-v $(pwd)/handlers.toml:/app/handlers.toml \
-v /var/run/docker.sock:/var/run/docker.sock \
-e DAEMON_QUEUE_TYPE=hybrid \
mshelia/taskdaemon
echo "Waiting for startup..."
sleep 3
# Queue task
TASK_ID=$(curl -s -X POST http://localhost:8080/queue \
-H "Content-Type: application/json" \
-d '{"type": "greet", "data": {"name": "TaskDaemon"}}' | jq -r '.task_id')
echo "Task ID: $TASK_ID"
sleep 2
# Get result
curl -s http://localhost:8080/api/tasks/$TASK_ID | jq
# Cleanup
docker stop taskdaemon && docker rm taskdaemon
Next Steps