Module apalis_sql::postgres 
source · Available on crate feature 
postgres only.Expand description
Postgres storage for apalis. Uses NOTIFY and SKIP LOCKED
§apalis-postgres
Allows using postgres as a Backend
§Postgres Example
use apalis::prelude::*;
use email_service::Email;
#[tokio::main]
async fn main() -> std::io::Result<()> {
    std::env::set_var("RUST_LOG", "debug,sqlx::query=error");
    let database_url = std::env::var("DATABASE_URL").expect("Must specify url to db");
    let pool = PgPool::connect(&database_url).await.unwrap();
     
    PostgresStorage::setup(&pool).await.unwrap();
    let pg: PostgresStorage<Email> = PostgresStorage::new(pool);
    async fn send_email(job: Email, data: Data<usize>) -> Result<(), Error> {
        /// execute job
        Ok(())
    }
   // This can be even in another program/language
   // let query = "Select apalis.push_job('apalis::Email', json_build_object('subject', 'Test apalis', 'to', 'test1@example.com', 'text', 'Lorem Ipsum'));";
   // pg.execute(query).await.unwrap();
    Monitor::<TokioExecutor>::new()
        .register_with_count(4, {
            WorkerBuilder::new(&format!("tasty-avocado"))
                .data(0usize)
                .source(pg)
                .build_fn(send_email)
        })
        .run()
        .await
}Structs§
- A listener that listens to Postgres notifications
 - A postgres subscription
 - Represents a Storage that persists to Postgres
 
Type Aliases§
- An alias for
Pool, specialized for Postgres.