-
-
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.
Merge pull request #32 from geofmureithi/develop
Minor fixes
- Loading branch information
Showing
32 changed files
with
180 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "apalis" | ||
version = "0.3.4" | ||
version = "0.3.5" | ||
authors = ["Geoffrey Mureithi <[email protected]>"] | ||
description = "Simple, extensible multithreaded background job processing for Rust" | ||
repository = "https://github.com/geofmureithi/apalis" | ||
|
@@ -54,26 +54,26 @@ docsrs = ["document-features"] | |
|
||
|
||
[dependencies.apalis-redis] | ||
version = "0.3.4" | ||
version = "0.3.5" | ||
optional = true | ||
default-features = false | ||
path = "./packages/apalis-redis" | ||
|
||
[dependencies.apalis-sql] | ||
version = "0.3.4" | ||
version = "0.3.5" | ||
features = ["migrate"] | ||
optional = true | ||
default-features = false | ||
path = "./packages/apalis-sql" | ||
|
||
[dependencies.apalis-core] | ||
version = "0.3.4" | ||
version = "0.3.5" | ||
optional = true | ||
default-features = false | ||
path = "./packages/apalis-core" | ||
|
||
[dependencies.apalis-cron] | ||
version = "0.3.4" | ||
version = "0.3.5" | ||
optional = true | ||
default-features = false | ||
path = "./packages/apalis-cron" | ||
|
@@ -93,7 +93,7 @@ all-features = true | |
criterion = { version = "0.3", features=["async_tokio"] } | ||
serde = "1" | ||
tokio = { version = "1", features =["macros"] } | ||
apalis-redis = { version = "0.3.4", path = "./packages/apalis-redis" } | ||
apalis-redis = { version = "0.3.5", path = "./packages/apalis-redis" } | ||
|
||
[[bench]] | ||
name = "redis_benchmark" | ||
|
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 |
---|---|---|
|
@@ -37,6 +37,7 @@ apalis = { version = "0.3", features = ["redis"] } | |
use apalis::prelude::*; | ||
use apalis::redis::RedisStorage; | ||
use serde::{Deserialize, Serialize}; | ||
use anyhow::Result; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
struct Email { | ||
|
@@ -48,11 +49,11 @@ async fn email_service(job: Email, _ctx: JobContext) -> Result<JobResult, JobErr | |
} | ||
|
||
#[tokio::main] | ||
async fn main() -> std::io::Result<()> { | ||
async fn main() -> Result<()> { | ||
std::env::set_var("RUST_LOG", "debug"); | ||
env_logger::init(); | ||
let redis = std::env::var("REDIS_URL").expect("Missing env variable REDIS_URL"); | ||
let storage = RedisStorage::new(redis).await.unwrap(); | ||
let storage = RedisStorage::new(redis).await?; | ||
Monitor::new() | ||
.register_with_count(2, move || { | ||
WorkerBuilder::new(storage.clone()) | ||
|
@@ -68,14 +69,13 @@ Then | |
|
||
```rust | ||
//This can be in another part of the program or another application | ||
async fn produce_route_jobs(storage: &RedisStorage<Email>) { | ||
async fn produce_route_jobs(storage: &RedisStorage<Email>) -> Result<()> { | ||
let mut storage = storage.clone(); | ||
storage | ||
.push(Email { | ||
to: "[email protected]".to_string(), | ||
}) | ||
.await | ||
.unwrap(); | ||
.await?; | ||
} | ||
|
||
``` | ||
|
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
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
use anyhow::Result; | ||
use apalis::prelude::*; | ||
use apalis::{layers::TraceLayer, postgres::PostgresStorage}; | ||
|
||
use email_service::{send_email, Email}; | ||
|
||
async fn produce_jobs(storage: &PostgresStorage<Email>) { | ||
// The programatic way | ||
async fn produce_jobs(storage: &PostgresStorage<Email>) -> Result<()> { | ||
// The programmatic way | ||
let mut storage = storage.clone(); | ||
storage | ||
.push(Email { | ||
to: "[email protected]".to_string(), | ||
text: "Test backround job from Apalis".to_string(), | ||
text: "Test background job from Apalis".to_string(), | ||
subject: "Background email job".to_string(), | ||
}) | ||
.await | ||
.expect("Unable to push job"); | ||
.await?; | ||
// The sql way | ||
tracing::info!("You can also add jobs via sql query, run this: \n Select apalis.push_job('apalis::Email', json_build_object('subject', 'Test Apalis', 'to', '[email protected]', 'text', 'Lorem Ipsum'));") | ||
tracing::info!("You can also add jobs via sql query, run this: \n Select apalis.push_job('apalis::Email', json_build_object('subject', 'Test Apalis', 'to', '[email protected]', 'text', 'Lorem Ipsum'));"); | ||
Ok(()) | ||
} | ||
|
||
struct TracingListener; | ||
|
@@ -26,17 +26,17 @@ impl WorkerListener for TracingListener { | |
} | ||
|
||
#[tokio::main] | ||
async fn main() -> std::io::Result<()> { | ||
async fn main() -> Result<()> { | ||
std::env::set_var("RUST_LOG", "debug,sqlx::query=error"); | ||
tracing_subscriber::fmt::init(); | ||
let database_url = std::env::var("DATABASE_URL").expect("Must specify path to db"); | ||
|
||
let pg: PostgresStorage<Email> = PostgresStorage::connect(database_url).await.unwrap(); | ||
let pg: PostgresStorage<Email> = PostgresStorage::connect(database_url).await?; | ||
pg.setup() | ||
.await | ||
.expect("unable to run migrations for postgres"); | ||
|
||
produce_jobs(&pg).await; | ||
produce_jobs(&pg).await?; | ||
|
||
Monitor::new() | ||
.register_with_count(4, move |_| { | ||
|
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
use anyhow::Result; | ||
use apalis::{ | ||
layers::{Extension, TraceLayer}, | ||
prelude::*, | ||
redis::RedisStorage, | ||
}; | ||
|
||
use email_service::{send_email, Email}; | ||
|
||
async fn produce_jobs(mut storage: RedisStorage<Email>) { | ||
async fn produce_jobs(mut storage: RedisStorage<Email>) -> Result<()> { | ||
for _i in 0..10 { | ||
storage | ||
.push(Email { | ||
to: "[email protected]".to_string(), | ||
text: "Test backround job from Apalis".to_string(), | ||
text: "Test background job from Apalis".to_string(), | ||
subject: "Background email job".to_string(), | ||
}) | ||
.await | ||
.unwrap(); | ||
.await?; | ||
} | ||
Ok(()) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> std::io::Result<()> { | ||
async fn main() -> Result<()> { | ||
std::env::set_var("RUST_LOG", "debug"); | ||
|
||
tracing_subscriber::fmt::init(); | ||
|
||
let storage = RedisStorage::connect("redis://127.0.0.1/").await.unwrap(); | ||
let storage = RedisStorage::connect("redis://127.0.0.1/").await?; | ||
//This can be in another part of the program | ||
produce_jobs(storage.clone()).await; | ||
produce_jobs(storage.clone()).await?; | ||
|
||
Monitor::new() | ||
.register( | ||
|
Oops, something went wrong.