Skip to content

Commit bffbc5f

Browse files
tlongwell-blocknpub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757
andauthored
feat(push): deliver accepted relay events as wakes (#1866)
Signed-off-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub12gtutshhh76rx0jx697f32f9tffd4hhp3hx58fp4x6u4uemkm7sqf8f757 <5217c5c2f7bfb4333e46d17c98a9255a52dadee18dcd43a43536b95e6776dfa0@sprout-oss.stage.blox.sqprod.co>
1 parent 8b2dd6d commit bffbc5f

14 files changed

Lines changed: 1335 additions & 28 deletions

File tree

‎crates/buzz-db/src/lib.rs‎

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,116 @@ impl Db {
951951
event::get_events_by_ids(&self.pool, community_id, ids).await
952952
}
953953

954+
/// Exclusively claim the next due event-to-push matcher job.
955+
pub async fn claim_due_push_match(
956+
&self,
957+
lease_until: DateTime<Utc>,
958+
) -> Result<Option<push::ClaimedMatch>> {
959+
push::claim_due_match(&self.pool, lease_until).await
960+
}
961+
962+
/// Load active endpoint-enabled leases eligible for push matching.
963+
pub async fn active_push_match_leases(
964+
&self,
965+
community: CommunityId,
966+
) -> Result<Vec<push::MatchLease>> {
967+
push::active_match_leases(&self.pool, community).await
968+
}
969+
970+
/// Complete a matcher job if its claim fence is still held.
971+
pub async fn complete_push_match(&self, job: &push::ClaimedMatch) -> Result<bool> {
972+
push::complete_match(&self.pool, job).await
973+
}
974+
975+
/// Release a matcher claim for retry at the supplied time.
976+
pub async fn retry_push_match(
977+
&self,
978+
job: &push::ClaimedMatch,
979+
next: DateTime<Utc>,
980+
) -> Result<bool> {
981+
push::retry_match(&self.pool, job, next).await
982+
}
983+
984+
/// Idempotently enqueue a wake for a matched lease and event.
985+
pub async fn enqueue_push_wake(
986+
&self,
987+
community: CommunityId,
988+
author: &[u8],
989+
installation_id: &str,
990+
wake: push::NewWake<'_>,
991+
) -> Result<push::EnqueueWakeOutcome> {
992+
push::enqueue_wake(&self.pool, community, author, installation_id, wake).await
993+
}
994+
995+
/// Exclusively claim due wake jobs for one community.
996+
pub async fn claim_due_push_wakes(
997+
&self,
998+
community: CommunityId,
999+
limit: i64,
1000+
lease_until: DateTime<Utc>,
1001+
) -> Result<Vec<push::ClaimedWake>> {
1002+
push::claim_due_wakes(&self.pool, community, limit, lease_until).await
1003+
}
1004+
1005+
/// Revalidate a wake's claim, source event, and current lease before send.
1006+
pub async fn revalidate_push_wake(
1007+
&self,
1008+
community: CommunityId,
1009+
id: Uuid,
1010+
claim_id: Uuid,
1011+
) -> Result<push::RevalidateWakeOutcome> {
1012+
push::revalidate_wake_for_send(&self.pool, community, id, claim_id).await
1013+
}
1014+
1015+
/// Mark a fenced wake claim delivered.
1016+
pub async fn complete_push_wake(
1017+
&self,
1018+
community: CommunityId,
1019+
id: Uuid,
1020+
claim_id: Uuid,
1021+
) -> Result<bool> {
1022+
push::complete_wake(&self.pool, community, id, claim_id).await
1023+
}
1024+
1025+
/// Release a fenced wake claim for retry at the supplied time.
1026+
pub async fn retry_push_wake(
1027+
&self,
1028+
community: CommunityId,
1029+
id: Uuid,
1030+
claim_id: Uuid,
1031+
next: DateTime<Utc>,
1032+
) -> Result<bool> {
1033+
push::retry_wake(&self.pool, community, id, claim_id, next).await
1034+
}
1035+
1036+
/// Mark a fenced wake claim terminally failed.
1037+
pub async fn fail_push_wake(
1038+
&self,
1039+
community: CommunityId,
1040+
id: Uuid,
1041+
claim_id: Uuid,
1042+
) -> Result<bool> {
1043+
push::fail_wake(&self.pool, community, id, claim_id).await
1044+
}
1045+
1046+
/// Disable an endpoint only if the specified lease generation is current.
1047+
pub async fn disable_push_endpoint(
1048+
&self,
1049+
community: CommunityId,
1050+
author: &[u8],
1051+
installation_id: &str,
1052+
generation: i64,
1053+
) -> Result<bool> {
1054+
push::disable_endpoint_generation(
1055+
&self.pool,
1056+
community,
1057+
author,
1058+
installation_id,
1059+
generation,
1060+
)
1061+
.await
1062+
}
1063+
9541064
/// Atomically persist a validated kind:30350 event and its effective lease.
9551065
#[allow(clippy::too_many_arguments)]
9561066
pub async fn accept_push_lease_event(

‎crates/buzz-db/src/migration.rs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ mod tests {
549549
let mut migrations: Vec<_> = MIGRATOR.iter().collect();
550550
migrations.sort_by_key(|migration| migration.version);
551551

552-
assert_eq!(migrations.len(), 17);
552+
assert_eq!(migrations.len(), 18);
553553
assert_eq!(migrations[0].version, 1);
554554
assert_eq!(&*migrations[0].description, "initial schema");
555555
assert!(migrations[0]
@@ -765,6 +765,8 @@ mod tests {
765765
.as_str()
766766
.contains("_operator_global_tables"));
767767

768+
// Community archival and product feedback landed concurrently. Keep
769+
// both additive migrations in a single, unambiguous sequence.
768770
assert_eq!(migrations[15].version, 16);
769771
assert!(migrations[15]
770772
.sql
@@ -787,6 +789,15 @@ mod tests {
787789
.as_str()
788790
.contains("('product_feedback', 'deployment product inbox"));
789791
assert!(!migrations[0].sql.as_str().contains("product_feedback"));
792+
793+
// Matching is driven from a parent-table trigger so all partition and
794+
// internal insertion paths share the same crash-safe allowlist seam.
795+
assert_eq!(migrations[17].version, 18);
796+
let matcher = migrations[17].sql.as_str();
797+
assert!(matcher.contains("CREATE TABLE push_match_queue"));
798+
assert!(matcher.contains("AFTER INSERT ON events"));
799+
assert!(matcher.contains("NEW.kind IN (7, 9, 1059, 40007, 46010)"));
800+
assert!(!migrations[0].sql.as_str().contains("push_match_queue"));
790801
}
791802

792803
#[test]
@@ -1029,7 +1040,7 @@ mod tests {
10291040
run_migrations(&pool)
10301041
.await
10311042
.expect("retry succeeds after operator repair");
1032-
assert_eq!(applied_versions(&pool).await.last().copied(), Some(17));
1043+
assert_eq!(applied_versions(&pool).await.last().copied(), Some(18));
10331044
}
10341045

10351046
#[tokio::test]

0 commit comments

Comments
 (0)