Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix examples #480

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/basics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
11 changes: 4 additions & 7 deletions examples/basics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Email>) {
Expand Down Expand Up @@ -54,11 +52,10 @@ pub enum PanicError {
async fn send_email(
email: Email,
svc: Data<EmailService>,
worker_ctx: Data<WorkerCtx>,
worker_id: Data<WorkerId>,
worker: Worker<Context>,
cache: Data<ValidEmailCache>,
) -> 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);
Expand All @@ -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;
Expand All @@ -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");
Expand Down
10 changes: 4 additions & 6 deletions examples/catch-panic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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"]
3 changes: 1 addition & 2 deletions examples/catch-panic/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<Email>) -> Result<()> {
for i in 0..2 {
Expand Down
5 changes: 4 additions & 1 deletion examples/postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
7 changes: 5 additions & 2 deletions examples/postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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?;
Expand Down
Loading