steid

@jamesgill /

steid/src/domain/repository/webhook_delivery_repo.rs
Rust1.5 KBCode·Blame·History·Raw
1use super::RepositoryResult;
2use crate::domain::{WebhookDelivery, WebhookId};
3
4/// Persistence for [`WebhookDelivery`].
5///
6/// Append-only from the application's side: an attempt happened, and later attempts are
7/// new rows rather than edits to an old one.
8pub trait WebhookDeliveryRepository: Send + Sync {
9 /// One page of the attempts against a hook, newest first.
10 ///
11 /// `offset` and `limit` are the deliveries page's `?page=`; an offset past the end
12 /// is an empty page rather than an error, because a delivery log grows under the
13 /// reader and a bookmarked deep page goes stale by itself.
14 fn list_by_webhook(
15 &self,
16 webhook_id: &WebhookId,
17 offset: usize,
18 limit: usize,
19 ) -> impl Future<Output = RepositoryResult<Vec<WebhookDelivery>>> + Send;
20
21 /// How many attempts a hook has recorded, for the page numbers.
22 fn count_by_webhook(
23 &self,
24 webhook_id: &WebhookId,
25 ) -> impl Future<Output = RepositoryResult<usize>> + Send;
26
27 /// The single most recent attempt, for the status dot on a hook list.
28 ///
29 /// Asked for separately rather than taking the head of `list_by_webhook`, because a
30 /// list page asks it once per hook and wants one row back each time.
31 fn latest_by_webhook(
32 &self,
33 webhook_id: &WebhookId,
34 ) -> impl Future<Output = RepositoryResult<Option<WebhookDelivery>>> + Send;
35
36 fn save(&self, delivery: &WebhookDelivery)
37 -> impl Future<Output = RepositoryResult<()>> + Send;
38}