Skip to main content

Retry

Trait Retry 

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

Runs when the handler asked for the message again.

The default leaves the record unprocessed and runs no statement, so the next startup publishes it again.

§Examples

use ruststream_sqlx::{Outbox, outbox};

#[derive(Outbox, sqlx::FromRow)]
#[outbox(table = "outbox", custom(retry))]
pub struct OrderOutbox {
    #[field(id)]
    id: i64,
    #[field(name)]
    name: String,
    #[field(payload)]
    payload: Vec<u8>,
    #[field(processed_at)]
    processed_at: Option<DateTime<Utc>>,
}

// The service counts how often a consumer asked for a record again.
impl outbox::Retry<Postgres> for OrderOutbox {
    async fn retry(conn: &mut PgConnection, id: &i64) -> sqlx::Result<()> {
        sqlx::query("UPDATE outbox SET retries = retries + 1 WHERE id = $1")
            .bind(id)
            .execute(conn)
            .await?;
        Ok(())
    }
}

pub fn app(pool: PgPool) -> impl App {
    let tracking = outbox! { pool: pool, "orders" => OrderOutbox };
    RustStream::new(AppInfo::new("orders", "0.1.0"))
        .layer(tracking.layer())
        .publish_layer(tracking.publish_layer())
        .with_broker(MemoryBroker::new(), |b| {
            b.include(place).out_reply(Publish);
            b.include(fulfil);
            b.after_startup(Publish, tracking.republish());
        })
}

Required Methods§

Source

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

Runs the retry event for the record id after its handler finished.

§Errors

The database’s error; the record stays unprocessed, and the next startup publishes it again.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§