# {{ name }}

A worker project built with [iq-sdk](https://github.com/iq-company/iq-sdk).

## Setup

```bash
# Create virtual environment
python -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -e .

# Copy and configure environment
cp .env.template .env
# Edit .env with your site credentials
```

## Project Structure

```
{{ name }}/
├── config/
│   └── settings.yml      # Sites and tool configuration
├── .env                  # Environment variables
├── tools/                # Your tool implementations
├── docs/                 # Documentation
├── .devcontainer/        # VS Code DevContainer
├── .github/              # GitHub Actions
│   └── workflows/        # GitHub Actions workflows (docker.yml)
├── docker/               # Docker files
│   ├── Dockerfile.worker # Worker Dockerfile
│   └── docker-compose.yml # Docker compose file
├── .gitignore            # Git ignore rules
├── README.md             # Project documentation
└── pyproject.toml        # Project configuration
```

## Managing Sites

```bash
# List configured sites
iq site list

# Check site connectivity
iq site list --check

# Add a new site
iq site add production --host http://prod:3000 --api-key worker

# Remove a site
iq site drop production
```

## Creating Tools

```bash
iq tool create my-tool
```

Edit `tools/my_tool_1/my_tool_1_0.py` to implement your logic.

## Running Workers

```bash
# Run with default config
iq worker start

# Run with specific sites
iq worker start --site production --site staging

# Run with specific tools
iq worker start --tool my-tool --tool other-tool

# Run with custom thread settings
iq worker start --threads 8 --max-threads 16

# Run with autoscaling
iq worker start --autoscale

# Use different config file
iq -c production worker start
```

## Configuration

### Sites (config/settings.yml)

```yaml
# Default site
site:
  id: "default"
  host: "http://localhost:8000"
  api_key: "worker"
  tools:
    - "my-tool"

# Additional sites
sites:
  - id: "production"
    host: "http://prod.example.com:8000"
    api_key: "prod-worker"
    tools:
      - "my-tool"
```

### Secrets (Environment Variables)

API secrets should **never** be stored in config files. Use environment variables:

```bash
# Direct secret
export IQ_SITE_PRODUCTION_API_SECRET='your-secret'

# File reference (K8s/Docker style)
export IQ_SITE_PRODUCTION_API_SECRET_FILE='/run/secrets/prod-secret'

# For JSON/YAML secrets, extract with _API_SECRET_KEY:
export IQ_SITE_PRODUCTION_API_SECRET_FILE='/etc/secrets/creds.json'
export IQ_SITE_PRODUCTION_API_SECRET_KEY='credentials.api_secret'
```

### Site Override via ENV

Any site config can be overridden:

```bash
export IQ_SITE_PRODUCTION_HOST='http://new-host:3000'
export IQ_SITE_PRODUCTION_API_KEY='new-key'
```

### Define Sites via ENV

```bash
export IQ_SITE_PRODUCTION_ACTIVE=1
export IQ_SITE_PRODUCTION_HOST=http://prod:3000
export IQ_SITE_PRODUCTION_API_KEY=worker

export IQ_SITE_STAGING_ACTIVE=1
export IQ_SITE_STAGING_HOST=http://stage:3000
```

## Docker

Build with baker-cli:

```bash
baker plan --targets all
baker build --check local --targets all
baker build --check registry --push=on --targets all
```

## License

MIT
