Update to artist credit handling
This commit is contained in:
28
src/queue.rs
28
src/queue.rs
@@ -39,15 +39,39 @@ const RETRY_DELAYS: [Duration; 3] = [
|
||||
Duration::from_secs(600),
|
||||
];
|
||||
|
||||
/// Progress callback: (current, total, message).
|
||||
pub type ProgressFn = Box<dyn Fn(u64, u64, &str) + Send + Sync>;
|
||||
|
||||
/// Process all pending items in the download queue.
|
||||
pub async fn run_queue(
|
||||
conn: &DatabaseConnection,
|
||||
backend: &impl DownloadBackend,
|
||||
config: &BackendConfig,
|
||||
dry_run: bool,
|
||||
) -> DlResult<DlStats> {
|
||||
run_queue_with_progress(conn, backend, config, dry_run, None).await
|
||||
}
|
||||
|
||||
/// Process all pending items in the download queue, with optional progress reporting.
|
||||
pub async fn run_queue_with_progress(
|
||||
conn: &DatabaseConnection,
|
||||
backend: &impl DownloadBackend,
|
||||
config: &BackendConfig,
|
||||
dry_run: bool,
|
||||
on_progress: Option<ProgressFn>,
|
||||
) -> DlResult<DlStats> {
|
||||
let mut stats = DlStats::default();
|
||||
|
||||
// Count total for progress reporting
|
||||
let total = queries::downloads::list(conn, Some(DownloadStatus::Pending))
|
||||
.await
|
||||
.map(|v| v.len() as u64)
|
||||
.unwrap_or(0);
|
||||
|
||||
if let Some(ref cb) = on_progress {
|
||||
cb(0, total, "Starting downloads...");
|
||||
}
|
||||
|
||||
loop {
|
||||
let item = match queries::downloads::get_next_pending(conn).await? {
|
||||
Some(item) => item,
|
||||
@@ -56,6 +80,10 @@ pub async fn run_queue(
|
||||
|
||||
stats.downloads_attempted += 1;
|
||||
|
||||
if let Some(ref cb) = on_progress {
|
||||
cb(stats.downloads_attempted, total, &format!("Downloading: {}", item.query));
|
||||
}
|
||||
|
||||
tracing::info!(
|
||||
id = item.id,
|
||||
query = %item.query,
|
||||
|
||||
Reference in New Issue
Block a user