Skip to main content

Ack

Trait Ack 

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

Acknowledges a row: by default it deletes the row, or sets processed_at.

The service’s own acknowledgement takes the row out of what the claim selects: it deletes the row, moves it, or marks it in a column the claim passes over. A row left claimable is delivered again.

§Examples

use std::time::Duration;

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

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

impl Ack<Postgres> for Job {
    async fn ack(
        conn: &mut PgConnection,
        id: &i64,
    ) -> Result<(), sqlx::Error> {
        // The finished job moves to an archive in one statement.
        sqlx::query(
            "WITH done AS (DELETE FROM jobs WHERE id = $1 RETURNING *) \
             INSERT INTO jobs_done SELECT * FROM done",
        )
        .bind(id)
        .execute(conn)
        .await?;
        Ok(())
    }
}

Required Methods§

Source

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

Runs the ack 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§