pub trait DeadLetter<DB: Database>: InboxRow {
// Required method
fn dead_letter(
conn: &mut DB::Connection,
id: &Self::Id,
destination: &str,
) -> impl Future<Output = Result<(), Error>> + Send;
}Expand description
Moves a row whose attempts are spent to destination: by default it moves the row to that
group (on a table with a group column) or into that table.
The service’s own move takes the row out of what the claim selects; a row copied and left behind is moved again at every delivery.
§Examples
use std::time::Duration;
use ruststream_sqlx::{DeadLetter, Inbox};
use sqlx::{PgConnection, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "jobs", custom(dead_letter))]
pub struct Job {
#[field(id)]
id: i64,
#[field(payload)]
payload: Vec<u8>,
}
impl DeadLetter<Postgres> for Job {
async fn dead_letter(
conn: &mut PgConnection,
id: &i64,
destination: &str,
) -> Result<(), sqlx::Error> {
// One dead-letter table serves the whole service, whatever the destination names.
sqlx::query(
"WITH dead AS (DELETE FROM jobs WHERE id = $1 RETURNING *) \
INSERT INTO dead_jobs SELECT * FROM dead",
)
.bind(id)
.execute(conn)
.await?;
tracing::warn!(id, destination, "a job's attempts are spent");
Ok(())
}
}Required Methods§
Sourcefn dead_letter(
conn: &mut DB::Connection,
id: &Self::Id,
destination: &str,
) -> impl Future<Output = Result<(), Error>> + Send
fn dead_letter( conn: &mut DB::Connection, id: &Self::Id, destination: &str, ) -> impl Future<Output = Result<(), Error>> + Send
Runs the dead_letter 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".