Skip to content

CLI Reference

Start a task worker.

Terminal window
horsies worker <module> [OPTIONS]

Arguments:

ArgumentDescription
modulePython file or dotted module path containing Horsies instance

Options:

OptionDefaultDescription
--processes N1Number of worker processes
--loglevel LEVELINFODEBUG, INFO, WARNING, ERROR, CRITICAL
--max-claim-batch N2Max claims per queue per pass
--max-claim-per-worker N0Max total claimed tasks (0=auto)

Examples:

Terminal window
# Basic worker (module:app format, recommended)
horsies worker myapp.instance:app
# With 8 processes
horsies worker myapp.instance:app --processes=8
# Debug logging
horsies worker myapp.instance:app --loglevel=DEBUG
# Production settings
horsies worker myapp.instance:app --processes=8 --max-claim-batch=4 --loglevel=WARNING
# Using file path (also supported)
horsies worker app/configs/instance.py:app

Start the scheduler service.

Terminal window
horsies scheduler <module> [OPTIONS]

Arguments:

ArgumentDescription
modulePython file or dotted module path containing Horsies instance

Options:

OptionDefaultDescription
--loglevel LEVELINFODEBUG, INFO, WARNING, ERROR, CRITICAL

Examples:

Terminal window
# Basic scheduler
horsies scheduler myapp.instance:app
# Debug logging
horsies scheduler myapp.instance:app --loglevel=DEBUG

Validate configuration, task registration, workflow structure, and optionally broker connectivity without starting services. Runs the same validation that workers and schedulers perform at startup.

For details on validation phases, @app.workflow_builder, the guarantee model, and CI usage, see Startup Validation.

Terminal window
horsies check <module> [OPTIONS]

Arguments:

ArgumentDescription
moduleDotted module path or file path containing Horsies instance

Options:

OptionDefaultDescription
--loglevel LEVELWARNINGDEBUG, INFO, WARNING, ERROR, CRITICAL
--livefalseAlso test broker connectivity (SELECT 1)

Examples:

Terminal window
# Validate tasks, config, and workflows
horsies check myapp.instance:app
# Include broker connectivity check
horsies check myapp.instance:app --live

Fetch the full documentation locally as markdown files. Useful for AI agents (Claude Code, Cursor, Copilot, etc.) that need to read docs without web requests.

Terminal window
horsies get-docs [OPTIONS]

Options:

OptionDefaultDescription
--output DIR.horsies-docsOutput directory

Examples:

Terminal window
# Fetch docs to default location
horsies get-docs
# Custom output directory
horsies get-docs --output my-docs/
# Update existing docs (idempotent — overwrites cleanly)
horsies get-docs

Uses git sparse checkout when git is available, falls back to tarball download otherwise. No app instance or database connection required.

If you are using an AI coding agent from a source checkout, Horsies also ships guidance-oriented skill files in:

horsies/.agents/skills/

Available files:

  • SKILL.md — quick orientation and routing
  • tasks.md — task authoring, send/retry, serialization, error handling
  • workflows.md — DAG construction, handles, failure semantics, validation
  • configs.md — configuration, scheduling, CLI checks, environment variables

These files are documentation-focused (no bundled scripts) and are intended for on-demand loading by agents that support markdown skill files.

The recommended format is a dotted module path with an explicit variable name:

Terminal window
horsies worker myapp.instance:app

Where app is the variable name of your Horsies instance in the module.

File paths are also supported:

Terminal window
horsies worker app/configs/instance.py:app

Do not mix dotted module notation with a .py extension (e.g., myapp.instance.py). The CLI will reject this with a helpful error.

If the module contains exactly one Horsies instance, the :name suffix can be omitted — the CLI will auto-discover it. If multiple instances exist, the suffix is required.

instance.py
from horsies import Horsies, AppConfig, PostgresConfig
app = Horsies(AppConfig(...)) # Auto-discovered
@app.task("my_task")
def my_task():
...
app.discover_tasks(["myapp.tasks"])

Requirements:

  • Module must have exactly one Horsies instance (or use :name suffix)
  • Instance can have any variable name

Both commands handle graceful shutdown:

SignalBehavior
SIGTERMGraceful shutdown
SIGINT (Ctrl+C)Graceful shutdown

Workers wait for running tasks to complete before exiting.

CodeMeaning
0Clean shutdown
1Error (check logs)
Terminal window
DATABASE_URL=postgresql+psycopg://... horsies worker myapp.instance:app

Use in config:

import os
config = AppConfig(
broker=PostgresConfig(database_url=os.environ["DATABASE_URL"]),
)
[Unit]
Description=Horsies Worker
After=postgresql.service
[Service]
Type=simple
User=app
WorkingDirectory=/app
ExecStart=/usr/bin/horsies worker myapp.instance:app --processes=8
Restart=always
[Install]
WantedBy=multi-user.target
FROM python:3.13
WORKDIR /app
COPY . .
RUN pip install horsies
CMD ["horsies", "worker", "myapp.instance:app", "--processes=8"]
worker: horsies worker myapp.instance:app --processes=8
scheduler: horsies scheduler myapp.instance:app