Skip to main content

Deliverer

Struct Deliverer 

Source
pub struct Deliverer<Q, K> { /* private fields */ }
Expand description

Queues activities and sends them.

Implementations§

Source§

impl<Q: Queue, K: SenderKeys> Deliverer<Q, K>

Source

pub fn new(queue: Q, keys: K, client: Client, config: DelivererConfig) -> Self

Source

pub fn collection_synchronization<F, Fut>(self, header: F) -> Self
where F: Fn(String, Url) -> Fut + Send + Sync + 'static, Fut: Future<Output = Option<String>> + Send + 'static,

The Collection-Synchronization header (FEP-8fcf) a delivery made with Batch::synchronize_collection carries, as header, given the sender and the inbox, writes it when the delivery is made: the sender’s followers collection, the digest of its followers on the inbox’s server, and where they are listed (crate::synchronization::CollectionSynchronization). None sends none.

Source

pub fn breaker_store(self, store: impl BreakerStore) -> Self

Keep circuit breakers in store rather than in this deliverer’s memory.

Source

pub fn on_settled<F, Fut>(self, handler: F) -> Self
where F: Fn(Settled) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Await handler for every delivery that settles — delivered, refused for good, or skipped — before it leaves the queue: where an application does what is to follow a delivery having gone through, such as leaving the account a follower moved away from once the Follow of the new one has. A process that stops in between sends the delivery again, and calls handler again, so it is to be safe to repeat.

Source

pub fn skip_if( self, skip: impl Fn(&Url, &Value) -> bool + Send + Sync + 'static, ) -> Self

Drop, unsent, each delivery that skip, given its inbox and its activity, says no longer to send, when it comes due: where an application stops delivering to a server it has marked unavailable since the delivery was queued, as Mastodon does for all but a Follow. A skipped delivery is complete, and neither attempted nor failed; skip is asked as often as a delivery comes due, so it is to answer from memory.

Source

pub fn on_attempt( self, handler: impl Fn(&DeliveryAttempt) + Send + Sync + 'static, ) -> Self

Call handler after every attempt at a delivery, whatever came of it: where an application keeps its own account of which servers answer, as Mastodon’s delivery failure tracker does.

Source

pub fn on_failure( self, handler: impl Fn(&DeliveryFailure) + Send + Sync + 'static, ) -> Self

Call handler for every delivery given up on, which is where an application marks a server that answered 410 as gone.

Source

pub fn queue(&self) -> &Q

The queue backend deliveries wait in.

Source

pub async fn send( &self, sender: &str, activity: &Value, inboxes: impl IntoIterator<Item = Url>, ) -> Result<(), QueueError>

Queue activity, signed by sender, for each of inboxes, once each.

§Errors

When the backend cannot queue them.

Source

pub async fn send_batch( &self, sender: &str, activity: &Value, inboxes: impl IntoIterator<Item = Url>, batch: &Batch, ) -> Result<(), QueueError>

Deliverer::send, in batch: tagged, given up on at its deadline, and sent after the deliveries queued before it with its ordering key.

§Errors

When the backend cannot queue them.

Source

pub async fn send_portable( &self, sender: &str, activity: &Value, inboxes: impl IntoIterator<Item = PortableInbox>, ) -> Result<(), QueueError>

Queue activity, signed by sender, for each portable inbox, once each: sent to the inbox at its first gateway that accepts it, of the first MAX_GATEWAYS it lists that are origins.

§Errors

When the backend cannot queue them.

Source

pub async fn run(&self)

Send what is queued, forever.

A backend error is waited out and retried, never returned: the loop is what keeps federation going, and a database that is briefly away should not stop it.

Source

pub async fn run_until(&self, stop: impl Future<Output = ()>)

Send what is queued until stop completes.

concurrency deliveries are kept in flight: as each finishes, its slot is taken by the next due delivery, claimed a few slots at a time rather than one round trip per delivery. A slow or silent inbox holds one slot for as long as it takes, not a whole batch — sending a batch and waiting for all of it held every healthy delivery claimed with a server that never answered until the client gave up on it.

Once stop has completed nothing more is claimed, and what is in flight is finished first, so that a server shutting down does not drop deliveries in the middle of sending them.

Source

pub async fn run_once(&self) -> Result<usize, QueueError>

Claim one batch and send it. Returns how many deliveries it held.

§Errors

When the backend cannot be read.

Auto Trait Implementations§

§

impl<Q, K> !Freeze for Deliverer<Q, K>

§

impl<Q, K> !RefUnwindSafe for Deliverer<Q, K>

§

impl<Q, K> !UnwindSafe for Deliverer<Q, K>

§

impl<Q, K> Send for Deliverer<Q, K>
where Q: Send, K: Send,

§

impl<Q, K> Sync for Deliverer<Q, K>
where Q: Sync, K: Sync,

§

impl<Q, K> Unpin for Deliverer<Q, K>
where Q: Unpin, K: Unpin,

§

impl<Q, K> UnsafeUnpin for Deliverer<Q, K>
where Q: UnsafeUnpin, K: 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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

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

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