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

# Task Selection Strategies

> Configure how tasks are picked from the queue

# Task Selection Strategies

Task selection controls the order in which tasks are dequeued for processing. This is a global setting that applies to all task types.

## Available Strategies

### FIFO (Default)

First-In-First-Out. Tasks are processed in the order they were queued.

```bash theme={null}
DAEMON_TASK_SELECTION=fifo
```

**Best for:** General workloads, fairness guarantees, predictable ordering.

### LIFO

Last-In-First-Out. Most recently queued tasks are processed first.

```bash theme={null}
DAEMON_TASK_SELECTION=lifo
```

**Best for:** Cache-hot data, reducing latency for recent requests, stack-like workloads.

### Priority

Tasks with higher priority values are processed first. Tasks at the same priority level use FIFO ordering.

```bash theme={null}
DAEMON_TASK_SELECTION=priority
```

**Best for:** Mixed workloads with urgent vs background tasks, SLA-based processing.

## Configuration

<Tabs>
  <Tab title="Environment Variable">
    ```bash theme={null}
    DAEMON_TASK_SELECTION=priority
    ```
  </Tab>

  <Tab title="CLI Flag">
    ```bash theme={null}
    ./task-daemon --task-selection priority
    ```
  </Tab>

  <Tab title="Docker">
    ```yaml docker-compose.yml theme={null}
    services:
      taskdaemon:
        image: mshelia/taskdaemon:latest
        environment:
          - DAEMON_TASK_SELECTION=priority
    ```
  </Tab>
</Tabs>

## Using Priority

When using the `priority` strategy, queue tasks with a priority value (0-100):

```bash theme={null}
# High priority task (processed first)
curl -X POST http://localhost:8080/queue \
  -H "Content-Type: application/json" \
  -d '{"type": "urgent", "data": {...}, "priority": 100}'

# Normal priority (default is 50)
curl -X POST http://localhost:8080/queue \
  -H "Content-Type: application/json" \
  -d '{"type": "normal", "data": {...}}'

# Low priority task (processed last)
curl -X POST http://localhost:8080/queue \
  -H "Content-Type: application/json" \
  -d '{"type": "background", "data": {...}, "priority": 0}'
```

<Info>
  Priority range is 0 (lowest) to 100 (highest). Default priority is 50 if not specified.
</Info>

## Comparison

| Strategy | Order                  | Use Case                     |
| -------- | ---------------------- | ---------------------------- |
| FIFO     | Oldest first           | Fair processing, predictable |
| LIFO     | Newest first           | Cache locality, recent data  |
| Priority | Highest priority first | Urgent tasks, SLAs           |
