Skip to content

Configuring Horsies

  • PostgreSQL 12+
  • Stable Rust
Terminal window
cargo add horsies
use horsies::{
Horsies, AppConfig, QueueMode, CustomQueueConfig,
};
let config = AppConfig::for_database_url(
"postgresql://user:password@localhost:5432/mydb"
);
let mut app = Horsies::new(config)?;

Different operations have different urgency levels can be defined with priority values. 1-100 where 1 is priority numero uno.

use horsies::{Horsies, AppConfig, QueueMode, CustomQueueConfig};
let config = AppConfig {
queue_mode: QueueMode::Custom,
custom_queues: Some(vec![
CustomQueueConfig { name: "urgent".into(), priority: 1, max_concurrency: 10 },
CustomQueueConfig { name: "standard".into(), priority: 50, max_concurrency: 20 },
CustomQueueConfig { name: "low".into(), priority: 100, max_concurrency: 5 },
]),
..AppConfig::for_database_url(
"postgresql://user:password@localhost:5432/db_name"
)
};
let mut app = Horsies::new(config)?;
QueuePriorityUse Case
urgent1The most important queue
standard50Things in between
low100The least important, can wait

Tasks are registered explicitly at startup. Each #[task] macro generates a companion module with a register function:

// Register individual tasks
add_numbers::register(&mut app)?;
process_data::register(&mut app)?;

There is no module auto-discovery. Each task must be registered before the worker starts.

app.run_worker().await?;

Or with custom config:

use horsies::WorkerConfig;
app.run_worker_with(WorkerConfig {
concurrency: 50,
..Default::default()
}).await?;