extern crate dbq;
extern crate postgres;
extern crate serde_json;
use std::error::Error;
use std::result::Result;
use std::thread;
use std::time::Duration;
#[derive(Clone)]
struct HelloHandler {}
fn main() -> Result<(), Box<Error>> {
let db_conn_params = "postgres://postgres:password@localhost/dbq";
let conn = postgres::Connection::connect(db_conn_params, postgres::TlsMode::None)?;
let schema_config = dbq::SchemaConfig::default();
dbq::run_migrations(&schema_config, &conn, Some(646_271)).unwrap();
let queue = dbq::Queue::new(schema_config, "example_simple".to_string());
queue.enqueue("job_a", serde_json::Value::Null, 3, &conn)?;
let workers_config =
dbq::WorkerPoolConfig::new(queue, db_conn_params, HelloHandler {})?;
let workers = dbq::WorkerPool::start(workers_config);
thread::sleep(Duration::new(1, 0));
workers.join();
Ok(())
}
impl dbq::Handler for HelloHandler {
type Error = std::io::Error;
fn handle(&self, _ctx: dbq::JobContext) -> Result<(), Self::Error> {
println!("Hello!");
Ok(())
}
}