Skip to main content

Retry

Trait Retry 

Source
pub trait Retry<DB: Database>: InboxRow {
    // Required method
    fn retry(
        conn: &mut DB::Connection,
        id: &Self::Id,
    ) -> impl Future<Output = Result<(), Error>> + Send;
}
Expand description

Releases a row for another attempt at once: by default it counts the attempt, or leaves the row for the rollback to release; in the lease form it clears the lease.

In the lease form the row comes back once locked_until no longer holds it: the service’s own retry clears the column to release the row at once, and otherwise the row waits for its lease to run out.

§Examples

use std::time::Duration;

use ruststream_sqlx::{Retry, Inbox};
use sqlx::{PgConnection, Postgres};

#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "jobs", custom(retry))]
pub struct Job {
    #[field(id)]
    id: i64,
    #[field(payload)]
    payload: Vec<u8>,
}

impl Retry<Postgres> for Job {
    async fn retry(
        conn: &mut PgConnection,
        id: &i64,
    ) -> Result<(), sqlx::Error> {
        sqlx::query("UPDATE jobs SET tries = tries + 1 WHERE id = $1")
            .bind(id)
            .execute(conn)
            .await?;
        Ok(())
    }
}

Required Methods§

Source

fn retry( conn: &mut DB::Connection, id: &Self::Id, ) -> impl Future<Output = Result<(), Error>> + Send

Runs the retry 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".

Implementors§