-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* api: for redis and sqlite * Version: 0.6.0-alpha.1 Changelog: - Redis storage doesnt require pool to be clone. Allows use of deadpool-redis among others. - Namespace is picked by default for `new` methods. * fix: docs and tests * lint: cargo clippy and fmt * postgres: add a listener example
- Loading branch information
1 parent
2fec565
commit bcbb015
Showing
27 changed files
with
610 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "redis-deadpool" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
deadpool-redis = { version = "0.15.1" } | ||
anyhow = "1" | ||
tokio = { version = "1", features = ["full"] } | ||
apalis = { path = "../../", features = ["redis", "timeout"] } | ||
serde = "1" | ||
env_logger = "0.10" | ||
tracing-subscriber = "0.3.11" | ||
chrono = { version = "0.4", default-features = false, features = ["clock"] } | ||
email-service = { path = "../email-service" } | ||
rmp-serde = "1.3" | ||
|
||
|
||
[dependencies.tracing] | ||
default-features = false | ||
version = "0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use std::time::Duration; | ||
|
||
use anyhow::Result; | ||
use apalis::prelude::*; | ||
use apalis::redis::RedisStorage; | ||
|
||
use deadpool_redis::{Config, Connection, Runtime}; | ||
use email_service::{send_email, Email}; | ||
use tracing::info; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
std::env::set_var("RUST_LOG", "debug"); | ||
|
||
tracing_subscriber::fmt::init(); | ||
|
||
let config = apalis::redis::Config::default() | ||
.set_namespace("apalis::redis-dead-pool") | ||
.set_max_retries(5); | ||
|
||
let cfg = Config::from_url("redis://127.0.0.1/"); | ||
let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap(); | ||
let conn = pool.get().await.unwrap(); | ||
let mut storage = RedisStorage::new_with_config(conn, config); | ||
// This can be in another part of the program | ||
produce_jobs(&mut storage).await?; | ||
|
||
let worker = WorkerBuilder::new("rango-tango") | ||
.with_storage(storage) | ||
.data(pool) | ||
.build_fn(send_email); | ||
|
||
Monitor::<TokioExecutor>::new() | ||
.register_with_count(2, worker) | ||
.shutdown_timeout(Duration::from_millis(5000)) | ||
.run_with_signal(async { | ||
tokio::signal::ctrl_c().await?; | ||
info!("Monitor starting shutdown"); | ||
Ok(()) | ||
}) | ||
.await?; | ||
info!("Monitor shutdown complete"); | ||
Ok(()) | ||
} | ||
|
||
async fn produce_jobs(storage: &mut RedisStorage<Email, Connection>) -> Result<()> { | ||
for index in 0..10 { | ||
storage | ||
.push(Email { | ||
to: index.to_string(), | ||
text: "Test background job from apalis".to_string(), | ||
subject: "Background email job".to_string(), | ||
}) | ||
.await?; | ||
} | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.