Skip to content

Fix Redis fallback ack_deadline_ms handling by updating message IDs … #118

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
41 changes: 22 additions & 19 deletions omniqueue/src/backends/redis/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,32 @@ async fn receive_with_timeout<R: RedisConnection>(
consumer: &RedisConsumer<R>,
timeout: Duration,
) -> Result<Option<Delivery>> {
let payload: Option<Vec<u8>> = consumer
.redis
.get()
.await
.map_err(QueueError::generic)?
.brpoplpush(
&consumer.queue_key,
&consumer.processing_queue_key,
// The documentation at https://redis.io/docs/latest/commands/brpoplpush/ does not
// state what unit the timeout is, but `BLPOP` and `BLMPOP` have similar timeout
// parameters that are documented as being seconds.
timeout.as_secs_f64(),
)
let mut conn = consumer.redis.get().await.map_err(QueueError::generic)?;

let payload: Option<Vec<u8>> = conn
.brpop(&consumer.queue_key, timeout.as_secs_f64())
.await
.map_err(QueueError::generic)?;

match payload {
Some(old_payload) => Some(internal_to_delivery(
internal_from_list(&old_payload)?.into(),
consumer,
old_payload,
))
.transpose(),
Some(old_payload) => {
// Creating a new payload with a new timestamp
// this is done to avoid the message being re-enqueued
// too early!
let new_payload = internal_to_list_payload(internal_from_list(&old_payload)?);

let _: () = conn
.lpush(&consumer.processing_queue_key, &new_payload)
.await
.map_err(QueueError::generic)?;

Some(internal_to_delivery(
internal_from_list(&new_payload)?.into(),
consumer,
new_payload,
))
.transpose()
}
None => Ok(None),
}
}
Expand Down
Loading