From a8891fb0f67eb7edad452750d4988b7340c7dbe2 Mon Sep 17 00:00:00 2001 From: geofmureithi Date: Tue, 10 Dec 2024 07:51:17 +0300 Subject: [PATCH] chore: fix examples --- examples/basics/Cargo.toml | 5 ++++- examples/basics/src/main.rs | 11 ++++------- examples/catch-panic/Cargo.toml | 10 ++++------ examples/catch-panic/src/main.rs | 3 +-- examples/postgres/Cargo.toml | 5 ++++- examples/postgres/src/main.rs | 7 +++++-- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/examples/basics/Cargo.toml b/examples/basics/Cargo.toml index 9016a8c..a60cb96 100644 --- a/examples/basics/Cargo.toml +++ b/examples/basics/Cargo.toml @@ -9,7 +9,10 @@ license = "MIT OR Apache-2.0" thiserror = "2.0.0" tokio = { version = "1", features = ["full"] } apalis = { path = "../../", features = ["limit", "catch-panic"] } -apalis-sql = { path = "../../packages/apalis-sql", features = ["sqlite"] } +apalis-sql = { path = "../../packages/apalis-sql", features = [ + "sqlite", + "tokio-comp", +] } serde = "1" tracing-subscriber = "0.3.11" email-service = { path = "../email-service" } diff --git a/examples/basics/src/main.rs b/examples/basics/src/main.rs index 82043b9..cc8cf34 100644 --- a/examples/basics/src/main.rs +++ b/examples/basics/src/main.rs @@ -12,8 +12,6 @@ use layer::LogLayer; use tracing::{log::info, Instrument, Span}; -type WorkerCtx = Context; - use crate::{cache::ValidEmailCache, service::EmailService}; async fn produce_jobs(storage: &SqliteStorage) { @@ -54,11 +52,10 @@ pub enum PanicError { async fn send_email( email: Email, svc: Data, - worker_ctx: Data, - worker_id: Data, + worker: Worker, cache: Data, ) -> Result<(), ServiceError> { - info!("Job started in worker {:?}", worker_id); + info!("Job started in worker {:?}", worker.id()); let cache_clone = cache.clone(); let email_to = email.to.clone(); let res = cache.get(&email_to); @@ -70,7 +67,7 @@ async fn send_email( // Its also possible to acquire context types and clone them into the futures context. // They will also be gracefully shutdown if [`Monitor`] has a shutdown signal tokio::spawn( - worker_ctx.track( + worker.track( async move { if cache::fetch_validity(email_to, &cache_clone).await { svc.send(email).await; @@ -94,7 +91,7 @@ async fn send_email( async fn main() -> Result<(), std::io::Error> { std::env::set_var("RUST_LOG", "debug,sqlx::query=error"); tracing_subscriber::fmt::init(); - let pool = SqlitePool::connect("sqlite::memory").await.unwrap(); + let pool = SqlitePool::connect("sqlite::memory:").await.unwrap(); SqliteStorage::setup(&pool) .await .expect("unable to run migrations for sqlite"); diff --git a/examples/catch-panic/Cargo.toml b/examples/catch-panic/Cargo.toml index e53eed1..6e03154 100644 --- a/examples/catch-panic/Cargo.toml +++ b/examples/catch-panic/Cargo.toml @@ -8,7 +8,10 @@ repository.workspace = true anyhow = "1" tokio = { version = "1", features = ["full"] } apalis = { path = "../../", features = ["limit", "tracing", "catch-panic"] } -apalis-sql = { path = "../../packages/apalis-sql", features = ["sqlite"] } +apalis-sql = { path = "../../packages/apalis-sql", features = [ + "sqlite", + "tokio-comp", +] } serde = { version = "1", features = ["derive"] } tracing-subscriber = "0.3.11" email-service = { path = "../email-service" } @@ -17,8 +20,3 @@ email-service = { path = "../email-service" } [dependencies.tracing] default-features = false version = "0.1" - -[dependencies.sqlx] -version = "0.8" -default-features = false -features = ["sqlite", "runtime-tokio"] diff --git a/examples/catch-panic/src/main.rs b/examples/catch-panic/src/main.rs index de87e09..7b77567 100644 --- a/examples/catch-panic/src/main.rs +++ b/examples/catch-panic/src/main.rs @@ -1,10 +1,9 @@ use anyhow::Result; use apalis::prelude::*; -use apalis_sql::sqlite::SqliteStorage; +use apalis_sql::{sqlite::SqliteStorage, sqlx::SqlitePool}; use email_service::Email; -use sqlx::SqlitePool; async fn produce_emails(storage: &mut SqliteStorage) -> Result<()> { for i in 0..2 { diff --git a/examples/postgres/Cargo.toml b/examples/postgres/Cargo.toml index 151c8a4..c5d46a8 100644 --- a/examples/postgres/Cargo.toml +++ b/examples/postgres/Cargo.toml @@ -8,7 +8,10 @@ license = "MIT OR Apache-2.0" [dependencies] anyhow = "1" apalis = { path = "../../", features = ["retry"] } -apalis-sql = { path = "../../packages/apalis-sql", features = ["postgres"] } +apalis-sql = { path = "../../packages/apalis-sql", features = [ + "postgres", + "tokio-comp", +] } serde = "1" tracing-subscriber = "0.3.11" chrono = { version = "0.4", default-features = false, features = ["clock"] } diff --git a/examples/postgres/src/main.rs b/examples/postgres/src/main.rs index 1b4ba9b..c62c1d1 100644 --- a/examples/postgres/src/main.rs +++ b/examples/postgres/src/main.rs @@ -2,7 +2,10 @@ use anyhow::Result; use apalis::layers::retry::RetryPolicy; use apalis::prelude::*; -use apalis_sql::postgres::{PgListen, PgPool, PostgresStorage}; +use apalis_sql::{ + postgres::{PgListen, PgPool, PostgresStorage}, + Config, +}; use email_service::{send_email, Email}; use tracing::{debug, info}; @@ -32,7 +35,7 @@ async fn main() -> Result<()> { .await .expect("unable to run migrations for postgres"); - let mut pg = PostgresStorage::new(pool.clone()); + let mut pg = PostgresStorage::new_with_config(pool.clone(), Config::new("apalis::Email")); produce_jobs(&mut pg).await?; let mut listener = PgListen::new(pool).await?;