- add admin POST /api/v1/admin/reindex-search endpoint + event-driven handler - backfill persons from movie_cast/movie_crew into persons table - paginate person list_page/backfill_from_credits_batch to cap memory - concurrent worker event dispatch with semaphore (max 8) - graceful worker shutdown (drain in-flight tasks on SIGINT) - always ack events, log handler errors as warnings (no infinite retry) - NATS ack_wait 600s, AtomicBool guard against concurrent reindex - add username/display_name to UserSummaryDto and users list - add person_id to CastMemberDto/CrewMemberDto via get_movie_profile use case - add movie_id to wrapup MovieRef, person_id to wrapup PersonStat - thread tmdb_person_id through wrapup cast pipeline - add is_federated to FeedEntryDto - cap orphaned persons query with LIMIT 500 - add SPA link to classic site footer
134 lines
3.2 KiB
Rust
134 lines
3.2 KiB
Rust
use async_trait::async_trait;
|
|
use chrono::NaiveDateTime;
|
|
|
|
use crate::{
|
|
errors::DomainError,
|
|
value_objects::{ExternalMetadataId, MovieId, PosterPath, Rating, ReviewId, UserId, WrapUpId},
|
|
};
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub enum DomainEvent {
|
|
ReviewLogged {
|
|
review_id: ReviewId,
|
|
movie_id: MovieId,
|
|
user_id: UserId,
|
|
rating: Rating,
|
|
watched_at: NaiveDateTime,
|
|
},
|
|
ReviewUpdated {
|
|
review_id: ReviewId,
|
|
movie_id: MovieId,
|
|
user_id: UserId,
|
|
rating: Rating,
|
|
watched_at: NaiveDateTime,
|
|
},
|
|
MovieDiscovered {
|
|
movie_id: MovieId,
|
|
external_metadata_id: ExternalMetadataId,
|
|
},
|
|
MovieDeleted {
|
|
movie_id: MovieId,
|
|
poster_path: Option<PosterPath>,
|
|
},
|
|
UserUpdated {
|
|
user_id: UserId,
|
|
},
|
|
ReviewDeleted {
|
|
review_id: ReviewId,
|
|
user_id: UserId,
|
|
},
|
|
MovieEnrichmentRequested {
|
|
movie_id: MovieId,
|
|
external_metadata_id: String,
|
|
},
|
|
ImageStored {
|
|
key: String,
|
|
},
|
|
WatchlistEntryAdded {
|
|
user_id: UserId,
|
|
movie_id: MovieId,
|
|
movie_title: String,
|
|
release_year: u16,
|
|
external_metadata_id: Option<String>,
|
|
added_at: chrono::NaiveDateTime,
|
|
},
|
|
WatchlistEntryRemoved {
|
|
user_id: UserId,
|
|
movie_id: MovieId,
|
|
},
|
|
FollowAccepted {
|
|
local_user_id: UserId,
|
|
remote_actor_url: String,
|
|
outbox_url: String,
|
|
},
|
|
BackfillFollower {
|
|
owner_user_id: UserId,
|
|
follower_inbox_url: String,
|
|
},
|
|
FederationDeliveryRequested {
|
|
inbox_url: String,
|
|
activity_json: String,
|
|
signing_actor_id: uuid::Uuid,
|
|
},
|
|
WatchEventIngested {
|
|
user_id: UserId,
|
|
title: String,
|
|
source: String,
|
|
},
|
|
WrapUpRequested {
|
|
wrapup_id: WrapUpId,
|
|
user_id: Option<UserId>,
|
|
start_date: chrono::NaiveDate,
|
|
end_date: chrono::NaiveDate,
|
|
},
|
|
WrapUpCompleted {
|
|
wrapup_id: WrapUpId,
|
|
},
|
|
SearchReindexRequested,
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait AckHandle: Send + Sync {
|
|
async fn ack(&self) -> Result<(), DomainError>;
|
|
async fn nack(&self) -> Result<(), DomainError>;
|
|
}
|
|
|
|
pub struct EventEnvelope {
|
|
pub event: DomainEvent,
|
|
ack: Box<dyn AckHandle>,
|
|
}
|
|
|
|
impl EventEnvelope {
|
|
pub fn new(event: DomainEvent, ack: Box<dyn AckHandle>) -> Self {
|
|
Self { event, ack }
|
|
}
|
|
|
|
pub async fn ack(self) -> Result<(), DomainError> {
|
|
self.ack.ack().await
|
|
}
|
|
|
|
pub async fn nack(self) -> Result<(), DomainError> {
|
|
self.ack.nack().await
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
use crate::value_objects::UserId;
|
|
|
|
#[test]
|
|
fn follow_accepted_matches() {
|
|
let uid = UserId::from_uuid(uuid::Uuid::new_v4());
|
|
let event = DomainEvent::FollowAccepted {
|
|
local_user_id: uid.clone(),
|
|
remote_actor_url: "https://remote.example/users/alice".to_string(),
|
|
outbox_url: "https://remote.example/users/alice/outbox".to_string(),
|
|
};
|
|
let DomainEvent::FollowAccepted { outbox_url, .. } = event else {
|
|
panic!("wrong variant");
|
|
};
|
|
assert_eq!(outbox_url, "https://remote.example/users/alice/outbox");
|
|
}
|
|
}
|