feat(daemon): refresh metadata on add
The metadata lane runs daily, so a series added a moment ago showed no seasons for up to 24 hours and a movie had no digital release date — the field §6.2 gates targeted search on. AppState now carries a MetadataCommand channel alongside the movie, episode and season ones. Both create handlers send on it after the row is committed, and a new daemon lane drains it. Its own task rather than an arm of manual::run: a refresh against TMDB can take a while and must not sit in front of an operator's manual search. The add never waits on TMDB and never fails because of it. A refresh that fails leaves metadata_refreshed_at NULL, which is what the daily sweep already treats as due, so the title is retried rather than lost. A command naming a title deleted in between finds no row and does nothing. METADATA_INTERVAL is unchanged. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
e9806d7a84
commit
d8797e1996
@@ -74,6 +74,8 @@ pub struct AppState {
|
||||
pending_episode_commands: Arc<tokio::sync::Mutex<mpsc::Receiver<EpisodeCommand>>>,
|
||||
season_commands: mpsc::Sender<SeasonCommand>,
|
||||
pending_season_commands: Arc<tokio::sync::Mutex<mpsc::Receiver<SeasonCommand>>>,
|
||||
metadata_commands: mpsc::Sender<MetadataCommand>,
|
||||
pending_metadata_commands: Arc<tokio::sync::Mutex<mpsc::Receiver<MetadataCommand>>>,
|
||||
}
|
||||
|
||||
/// Work explicitly requested through the movie API.
|
||||
@@ -104,6 +106,22 @@ pub enum SeasonCommand {
|
||||
Grab { season_id: i64, release_id: i64 },
|
||||
}
|
||||
|
||||
/// A title whose TMDB metadata should be refreshed now rather than on the
|
||||
/// daily lane's next tick (issue #176).
|
||||
///
|
||||
/// Sent when a title is added: a new series has no seasons at all until a
|
||||
/// refresh reveals them, and a new movie has no digital release date, so
|
||||
/// waiting up to a day is the difference between a usable page and an empty
|
||||
/// one. Unlike the other three commands this is not an operator action, so a
|
||||
/// full channel is dropped rather than reported — the scheduled sweep still
|
||||
/// owns the title, because a title that was never refreshed keeps
|
||||
/// `metadata_refreshed_at` NULL.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum MetadataCommand {
|
||||
Series { series_id: i64 },
|
||||
Movie { movie_id: i64 },
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
/// Build the state, including the shared HTTP client.
|
||||
///
|
||||
@@ -115,6 +133,7 @@ impl AppState {
|
||||
let (movie_commands, pending_movie_commands) = mpsc::channel(64);
|
||||
let (episode_commands, pending_episode_commands) = mpsc::channel(64);
|
||||
let (season_commands, pending_season_commands) = mpsc::channel(64);
|
||||
let (metadata_commands, pending_metadata_commands) = mpsc::channel(64);
|
||||
Ok(Self {
|
||||
http,
|
||||
upstreams: Arc::new(upstreams),
|
||||
@@ -125,6 +144,8 @@ impl AppState {
|
||||
pending_episode_commands: Arc::new(tokio::sync::Mutex::new(pending_episode_commands)),
|
||||
season_commands,
|
||||
pending_season_commands: Arc::new(tokio::sync::Mutex::new(pending_season_commands)),
|
||||
metadata_commands,
|
||||
pending_metadata_commands: Arc::new(tokio::sync::Mutex::new(pending_metadata_commands)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -162,6 +183,16 @@ impl AppState {
|
||||
self.pending_season_commands.lock().await.recv().await
|
||||
}
|
||||
|
||||
/// Wait for the next on-demand metadata refresh in the daemon's metadata
|
||||
/// lane.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// If every sender has been dropped.
|
||||
pub async fn next_metadata_command(&self) -> Option<MetadataCommand> {
|
||||
self.pending_metadata_commands.lock().await.recv().await
|
||||
}
|
||||
|
||||
pub(crate) fn http(&self) -> &reqwest::Client {
|
||||
&self.http
|
||||
}
|
||||
@@ -194,4 +225,14 @@ impl AppState {
|
||||
) -> Result<(), mpsc::error::TrySendError<SeasonCommand>> {
|
||||
self.season_commands.try_send(command)
|
||||
}
|
||||
|
||||
/// Ask the metadata lane to refresh one title now. Best effort by
|
||||
/// design: an add must not fail because the channel is full or because
|
||||
/// nothing is draining it, so the caller logs and carries on.
|
||||
pub(crate) fn send_metadata_command(
|
||||
&self,
|
||||
command: MetadataCommand,
|
||||
) -> Result<(), mpsc::error::TrySendError<MetadataCommand>> {
|
||||
self.metadata_commands.try_send(command)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user