> ## 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.

# Environment Variables

> Configure TaskDaemon via environment variables

# Environment Variables

Configure TaskDaemon via environment variables.

## Available Variables

| Variable                    | Default              | Description                                 |
| --------------------------- | -------------------- | ------------------------------------------- |
| `HANDLER_CONFIG`            | `handlers.toml`      | Path to handler configuration file          |
| `DAEMON_PORT`               | `8080`               | HTTP server port                            |
| `DAEMON_GRPC_PORT`          | `50051`              | gRPC server port                            |
| `DAEMON_WORKERS`            | `2`                  | Number of worker threads                    |
| `DAEMON_DB_PATH`            | `/tmp/task_queue.db` | SQLite database path                        |
| `DAEMON_DB_MAX_CONNECTIONS` | `20`                 | SQLite connection pool size                 |
| `DAEMON_QUEUE_TYPE`         | `sqlite`             | Queue type: `sqlite` or `hybrid`            |
| `DAEMON_TASK_SELECTION`     | `fifo`               | Task selection: `fifo`, `lifo`, `priority`  |
| `DAEMON_LOG_LEVEL`          | `info`               | Log level (trace, debug, info, warn, error) |
| `DAEMON_HOST`               | `0.0.0.0`            | HTTP server bind address                    |
| `DAEMON_MAX_RETRIES`        | `3`                  | Maximum retry attempts for failed tasks     |
| `DAEMON_TASK_TIMEOUT`       | `30`                 | Default task timeout in seconds             |

## Queue Types

<Tabs>
  <Tab title="sqlite">
    Standard SQLite-backed queue. Durable but slightly slower under high load.

    ```bash theme={null}
    DAEMON_QUEUE_TYPE=sqlite
    ```
  </Tab>

  <Tab title="hybrid">
    In-memory queue with SQLite persistence. Faster dequeue with durability.

    ```bash theme={null}
    DAEMON_QUEUE_TYPE=hybrid
    ```

    <Tip>
      Recommended for high-throughput workloads. Tasks are kept in memory for fast access but persisted to SQLite for crash recovery.
    </Tip>
  </Tab>
</Tabs>

## Task Selection

| Value      | Description                  |
| ---------- | ---------------------------- |
| `fifo`     | First-In-First-Out (default) |
| `lifo`     | Last-In-First-Out            |
| `priority` | Highest priority first       |

See [Task Selection Strategies](/configuration/task-selection) for details.

## Usage

### Docker

```bash theme={null}
docker run -d \
  -e DAEMON_WORKERS=100 \
  -e DAEMON_QUEUE_TYPE=hybrid \
  -e DAEMON_TASK_SELECTION=priority \
  -e DAEMON_DB_MAX_CONNECTIONS=50 \
  -e DAEMON_LOG_LEVEL=info \
  -v ./handlers.toml:/app/handlers.toml \
  -v /var/run/docker.sock:/var/run/docker.sock \
  mshelia/taskdaemon
```

### Docker Compose

```yaml theme={null}
services:
  taskdaemon:
    image: mshelia/taskdaemon:latest
    environment:
      - DAEMON_WORKERS=100
      - DAEMON_QUEUE_TYPE=hybrid
      - DAEMON_TASK_SELECTION=priority
      - DAEMON_DB_MAX_CONNECTIONS=50
      - DAEMON_LOG_LEVEL=info
    volumes:
      - ./handlers.toml:/app/handlers.toml
      - /var/run/docker.sock:/var/run/docker.sock
      - task-data:/data

volumes:
  task-data:
```

### Shell

```bash theme={null}
export DAEMON_WORKERS=100
export DAEMON_QUEUE_TYPE=hybrid
export DAEMON_TASK_SELECTION=fifo
./target/release/task-daemon --config handlers.toml
```

## CLI Arguments

CLI arguments override environment variables:

| CLI Flag           | Environment Variable    |
| ------------------ | ----------------------- |
| `--workers`        | `DAEMON_WORKERS`        |
| `--http-port`      | `DAEMON_PORT`           |
| `--grpc-port`      | `DAEMON_GRPC_PORT`      |
| `--db-path`        | `DAEMON_DB_PATH`        |
| `--log-level`      | `DAEMON_LOG_LEVEL`      |
| `--task-selection` | `DAEMON_TASK_SELECTION` |
| `--config`         | `HANDLER_CONFIG`        |

## Precedence

Configuration is applied in this order (later overrides earlier):

1. Default values
2. Environment variables
3. CLI arguments

```bash theme={null}
# DAEMON_WORKERS=4 in environment
# --workers 8 on command line
# Result: 8 workers (CLI wins)
```

## Performance Tuning

For high-throughput workloads:

```bash theme={null}
DAEMON_WORKERS=100              # Match to handler instances
DAEMON_QUEUE_TYPE=hybrid        # Faster dequeue
DAEMON_DB_MAX_CONNECTIONS=50    # More DB connections
DAEMON_TASK_SELECTION=fifo      # Predictable ordering
```

<Note>
  Set `DAEMON_WORKERS` to roughly match the total number of handler instances across all handlers for optimal utilization.
</Note>

## Log Levels

| Level   | Description              |
| ------- | ------------------------ |
| `trace` | Very detailed debugging  |
| `debug` | Debugging information    |
| `info`  | General operational info |
| `warn`  | Warning messages         |
| `error` | Error messages only      |
