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

Fix: mq example #355

Merged
merged 2 commits into from
Jul 9, 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
1 change: 0 additions & 1 deletion benches/storages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use apalis::{
postgres::{PgPool, PostgresStorage},
sqlite::{SqlitePool, SqliteStorage},
};
use apalis_redis::Config;
use criterion::*;
use futures::Future;
use paste::paste;
Expand Down
16 changes: 5 additions & 11 deletions examples/redis-mq-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ use apalis::{

use apalis_core::{
codec::json::JsonCodec,
layers::{Ack, AckLayer},
layers::{Ack, AckLayer, AckResponse},
};
use email_service::{send_email, Email};
use futures::{channel::mpsc, SinkExt};
use rsmq_async::{Rsmq, RsmqConnection, RsmqError};
use tokio::time::sleep;
use tower::layer::util::Identity;
use tracing::{error, info};

struct RedisMq<T> {
Expand Down Expand Up @@ -71,13 +70,9 @@ impl<T: Send> Ack<T> for RedisMq<T> {

type Error = RsmqError;

async fn ack(
&mut self,
worker_id: &WorkerId,
data: &Self::Acknowledger,
) -> Result<(), Self::Error> {
println!("Attempting to ACK {}", data);
self.conn.delete_message("email", data).await?;
async fn ack(&mut self, ack: AckResponse<String>) -> Result<(), Self::Error> {
println!("Attempting to ACK {}", ack.acknowledger);
self.conn.delete_message("email", &ack.acknowledger).await?;
Ok(())
}
}
Expand Down Expand Up @@ -141,8 +136,7 @@ async fn main() -> Result<()> {
codec: RedisCodec::new(Box::new(JsonCodec)),
config: Config::default(),
};
// This can be in another part of the program
// produce_jobs(&mut mq).await?;
produce_jobs(&mut mq).await?;

let worker = WorkerBuilder::new("rango-tango")
.layer(TraceLayer::new())
Expand Down
3 changes: 2 additions & 1 deletion packages/apalis-core/src/mq/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ pub trait MessageQueue<Message>: Backend<Request<Message>> {
type Error;

/// Enqueues a message to the queue.
fn enqueue(&mut self, message: Message) -> impl Future<Output = Result<(), Self::Error>> + Send;
fn enqueue(&mut self, message: Message)
-> impl Future<Output = Result<(), Self::Error>> + Send;

/// Attempts to dequeue a message from the queue.
/// Returns `None` if the queue is empty.
Expand Down
Loading