pub trait RetryAfter<DB: Database>: InboxRow {
// Required method
fn retry_after(
conn: &mut DB::Connection,
id: &Self::Id,
delay: Duration,
) -> impl Future<Output = Result<(), Error>> + Send;
}Expand description
Releases a row for another attempt after delay: by default it sets retry_after.
A row with this event, or a retry_after field, is redelivered by the database’s own
clock. The service’s own event delays a row only where the claim passes over it until
then: the default claim reads the retry_after field.
§Examples
use std::time::Duration;
use ruststream_sqlx::{RetryAfter, Inbox};
use sqlx::{PgConnection, Postgres};
use chrono::{DateTime, Utc};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "jobs", custom(retry_after))]
pub struct Job {
#[field(id)]
id: i64,
#[field(retry_after)]
retry_after: DateTime<Utc>,
#[field(payload)]
payload: Vec<u8>,
}
impl RetryAfter<Postgres> for Job {
async fn retry_after(
conn: &mut PgConnection,
id: &i64,
delay: Duration,
) -> Result<(), sqlx::Error> {
// The delay counts from the database's clock, whatever the host's says.
sqlx::query(
"UPDATE jobs SET retry_after = now() + make_interval(secs => $2) WHERE id = $1",
)
.bind(id)
.bind(delay.as_secs_f64())
.execute(conn)
.await?;
Ok(())
}
}Required Methods§
Sourcefn retry_after(
conn: &mut DB::Connection,
id: &Self::Id,
delay: Duration,
) -> impl Future<Output = Result<(), Error>> + Send
fn retry_after( conn: &mut DB::Connection, id: &Self::Id, delay: Duration, ) -> impl Future<Output = Result<(), Error>> + Send
Runs the retry_after event for the row id inside a transaction the crate commits: the claim’s, or in the lease form one that first confirms the row still holds the delivery’s lease.
§Errors
The database’s error; the transaction rolls back, and the row returns to the queue at once, or in the lease form once its lease runs out.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".