pub struct Deliverer<Q, K> { /* private fields */ }Expand description
Queues activities and sends them.
Implementations§
Source§impl<Q: Queue, K: SenderKeys> Deliverer<Q, K>
impl<Q: Queue, K: SenderKeys> Deliverer<Q, K>
pub fn new(queue: Q, keys: K, client: Client, config: DelivererConfig) -> Self
Sourcepub fn collection_synchronization<F, Fut>(self, header: F) -> Self
pub fn collection_synchronization<F, Fut>(self, header: F) -> Self
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.
Sourcepub fn breaker_store(self, store: impl BreakerStore) -> Self
pub fn breaker_store(self, store: impl BreakerStore) -> Self
Keep circuit breakers in store rather than in this deliverer’s
memory.
Sourcepub fn on_settled<F, Fut>(self, handler: F) -> Self
pub fn on_settled<F, Fut>(self, handler: F) -> Self
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.
Sourcepub fn skip_if(
self,
skip: impl Fn(&Url, &Value) -> bool + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn on_attempt(
self,
handler: impl Fn(&DeliveryAttempt) + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn on_failure(
self,
handler: impl Fn(&DeliveryFailure) + Send + Sync + 'static,
) -> Self
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.
Sourcepub async fn send(
&self,
sender: &str,
activity: &Value,
inboxes: impl IntoIterator<Item = Url>,
) -> Result<(), QueueError>
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.
Sourcepub async fn send_batch(
&self,
sender: &str,
activity: &Value,
inboxes: impl IntoIterator<Item = Url>,
batch: &Batch,
) -> Result<(), QueueError>
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.
Sourcepub async fn send_portable(
&self,
sender: &str,
activity: &Value,
inboxes: impl IntoIterator<Item = PortableInbox>,
) -> Result<(), QueueError>
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.
Sourcepub async fn run(&self)
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.
Sourcepub async fn run_until(&self, stop: impl Future<Output = ()>)
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.