> ## Documentation Index
> Fetch the complete documentation index at: https://taskdaemon.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get TaskDaemon running in under 5 minutes

# Quick Start

Get TaskDaemon running in under 5 minutes.

## Prerequisites

<Check>Docker installed and running</Check>

## Steps

<Steps>
  <Step title="Create a Handler">
    Create a new directory and add a simple Python handler:

    ```bash theme={null}
    mkdir taskdaemon-quickstart && cd taskdaemon-quickstart
    ```

    Create `handler.py`:

    ```python handler.py theme={null}
    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`:

    ```dockerfile Dockerfile.handler theme={null}
    FROM python:3.11-slim
    COPY handler.py /app/
    WORKDIR /app
    CMD ["python", "-u", "handler.py"]
    ```
  </Step>

  <Step title="Build the Handler Image">
    ```bash theme={null}
    docker build -f Dockerfile.handler -t my-greeter:latest .
    ```
  </Step>

  <Step title="Create Handler Config">
    Create `handlers.toml`:

    ```toml handlers.toml theme={null}
    [handlers.greet]
    image = "my-greeter:latest"
    instances = 2
    handler_selection = "round-robin"
    ```
  </Step>

  <Step title="Start TaskDaemon">
    ```bash theme={null}
    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:

    ```bash theme={null}
    docker logs taskdaemon
    ```

    You should see:

    ```
    INFO task_daemon: TaskDaemon started http_port=8080 grpc_port=50051 workers=2
    ```
  </Step>

  <Step title="Queue a Task">
    ```bash theme={null}
    curl -X POST http://localhost:8080/queue \
      -H "Content-Type: application/json" \
      -d '{"type": "greet", "data": {"name": "TaskDaemon"}}'
    ```

    Response:

    ```json theme={null}
    {"task_id":"550e8400-e29b-41d4-a716-446655440000"}
    ```
  </Step>

  <Step title="Check Result">
    ```bash theme={null}
    curl http://localhost:8080/api/tasks/<task_id>
    ```

    Response:

    ```json theme={null}
    {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "status": "completed",
      "result": {"message": "Hello, TaskDaemon!"}
    }
    ```
  </Step>
</Steps>

## Cleanup

```bash theme={null}
docker stop taskdaemon && docker rm taskdaemon
```

## Complete Script

Here's everything in one script:

<Accordion title="quickstart.sh">
  ```bash quickstart.sh theme={null}
  #!/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
  ```
</Accordion>

## Next Steps

<CardGroup cols={2}>
  <Card title="Use an SDK" icon="puzzle-piece" href="/handlers/python">
    Cleaner handler code with official SDKs
  </Card>

  <Card title="Sample Project" icon="github" href="https://github.com/jona62/TaskDaemon-Sample">
    Complete working example with C++ handler
  </Card>

  <Card title="Configure Strategies" icon="gear" href="/configuration/task-selection">
    FIFO, LIFO, or Priority task ordering
  </Card>

  <Card title="Add Monitoring" icon="chart-line" href="/monitoring/prometheus">
    Prometheus metrics and Grafana dashboards
  </Card>
</CardGroup>
