Skip to main content

RowBatch

Struct RowBatch 

Source
pub struct RowBatch<DB, Row>
where DB: QueueDatabase, Row: Events<DB> + QueueRow<Lane = RowLane>,
{ /* private fields */ }
Expand description

The rows one claim of a table in row mode took, which a batch handler borrows as one slice, &[Row], and the claims that settle them.

The rows lie in one vector in claim order, as the driver read them: the handler reads them where they lie, with no codec and no copy. Each row’s headers column was taken into its delivery’s headers when the batch was built, so the handler reads the column empty. A message assembled from a headers struct keeps its headers struct whole, and each delivery builds its header map from it on the first read. A claimed id without a row, and a row the driver could not read, follow the slice: the runtime settles them by the subscription’s decode policy, its error in the log. Every delivery of the batch holds its row in the table’s form, as a payload-mode batch’s deliveries do: one transaction for the whole batch in the row lock form, a lease the subscription extends while the handler runs in the lease form, a session that holds the row’s key in the advisory lock form.

A batch dropped before its deliveries settle (its handler panicked, the app shut down) returns its rows at once, as a dropped delivery does.

§Examples

use ruststream_sqlx::prelude::*;
use sqlx::PgPool;

/// A mail to send: the table has no payload column, so a handler takes the rows themselves.
#[derive(Debug, Clone, Inbox, sqlx::FromRow)]
#[inbox(table = "mail_jobs")]
pub struct SendEmail {
    #[field(id)]
    job_id: i64,
    recipient: String,
}

/// Each claim of up to 50 rows reaches the handler as one slice; each mail settles on its own.
#[subscriber(InboxQueue::<SendEmail>::new("mail"))]
async fn send(mails: &[SendEmail]) -> Vec<HandlerOutcome> {
    let mut outcomes = Vec::with_capacity(mails.len());
    for mail in mails {
        outcomes.push(if deliver(&mail.recipient).await {
            HandlerOutcome::ack()
        } else {
            HandlerOutcome::retry()
        });
    }
    outcomes
}

pub fn app(pool: PgPool) -> RustStream {
    RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
        b.include(send.batch(nonzero!(50)));
    })
}

Trait Implementations§

Source§

impl<DB, Row> CarriesBatch<Row> for RowBatch<DB, Row>
where DB: QueueDatabase, Row: Events<DB> + QueueRow<Lane = RowLane>,

Source§

fn carried(&self) -> &[Row]

The values the batch’s deliveries carry, in the order the batch yields its deliveries.
Source§

impl<DB, Row> Debug for RowBatch<DB, Row>
where DB: QueueDatabase, Row: Events<DB> + QueueRow<Lane = RowLane>,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DB, Row> IntoIterator for RowBatch<DB, Row>
where DB: QueueDatabase, Row: Events<DB> + QueueRow<Lane = RowLane>,

Source§

type Item = InboxDelivery<DB, Row>

The type of the elements being iterated over.
Source§

type IntoIter = RowDeliveries<DB, Row>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<DB, Row> !RefUnwindSafe for RowBatch<DB, Row>

§

impl<DB, Row> !UnwindSafe for RowBatch<DB, Row>

§

impl<DB, Row> Freeze for RowBatch<DB, Row>
where RowDeliveries<DB, Row>: Freeze,

§

impl<DB, Row> Send for RowBatch<DB, Row>
where RowDeliveries<DB, Row>: Send,

§

impl<DB, Row> Sync for RowBatch<DB, Row>
where RowDeliveries<DB, Row>: Sync,

§

impl<DB, Row> Unpin for RowBatch<DB, Row>
where RowDeliveries<DB, Row>: Unpin,

§

impl<DB, Row> UnsafeUnpin for RowBatch<DB, Row>
where RowDeliveries<DB, Row>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PublishedThrough<DefaultSlot> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more