Skip to content

Commit f57afa7

Browse files
Stream logs continuously during FFmpeg encoding
Instead of only flushing logs at specific milestones, now flush logs every 30 seconds during the FFmpeg encoding process. This ensures real-time visibility into long-running jobs (2+ hours). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8ed1bc4 commit f57afa7

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/jobs.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ async fn process_job(job: Job) -> Result<()> {
539539
let stdout = child.stdout.take();
540540
let queue_url_clone = job.webdav_config.queue_url.clone();
541541
let job_id_clone = job.id.clone();
542+
let rlog_clone = rlog.clone();
542543

543544
// Spawn a task to read and parse progress
544545
let progress_handle = tokio::spawn(async move {
@@ -552,9 +553,13 @@ async fn process_job(job: Job) -> Result<()> {
552553
let mut current_speed: Option<String> = None;
553554
let mut total_duration: Option<String> = None;
554555
let mut last_report = std::time::Instant::now();
556+
let mut last_log_flush = std::time::Instant::now();
555557
let mut progress_count = 0u32;
556558

557559
info!("Starting to read FFmpeg progress from stdout...");
560+
if let Some(ref logger) = rlog_clone {
561+
logger.info("Starting to read FFmpeg progress from stdout...");
562+
}
558563

559564
while let Ok(Some(line)) = lines.next_line().await {
560565
// Parse FFmpeg progress output format:
@@ -583,8 +588,12 @@ async fn process_job(job: Job) -> Result<()> {
583588
// End of a progress block - report to server (throttled)
584589
if last_report.elapsed() >= std::time::Duration::from_secs(2) {
585590
if let Some(queue_url) = &queue_url_clone {
586-
info!("Sending progress update #{}: frame={:?}, time={:?}, speed={:?}",
591+
let msg = format!("Progress update #{}: frame={:?}, time={:?}, speed={:?}",
587592
progress_count, current_frame, current_time, current_speed);
593+
info!("{}", msg);
594+
if let Some(ref logger) = rlog_clone {
595+
logger.info(&msg);
596+
}
588597
let progress = JobProgress {
589598
frame: current_frame,
590599
total_frames: None,
@@ -601,11 +610,26 @@ async fn process_job(job: Job) -> Result<()> {
601610
}
602611
last_report = std::time::Instant::now();
603612
}
613+
614+
// Flush logs every 30 seconds during encoding
615+
if last_log_flush.elapsed() >= std::time::Duration::from_secs(30) {
616+
if let Some(ref logger) = rlog_clone {
617+
logger.flush().await;
618+
}
619+
last_log_flush = std::time::Instant::now();
620+
}
604621
}
605622
}
606623
info!("Finished reading FFmpeg progress. Total progress blocks: {}", progress_count);
624+
if let Some(ref logger) = rlog_clone {
625+
logger.info(format!("Finished reading FFmpeg progress. Total progress blocks: {}", progress_count));
626+
logger.flush().await;
627+
}
607628
} else {
608629
warn!("No stdout available from FFmpeg process");
630+
if let Some(ref logger) = rlog_clone {
631+
logger.warn("No stdout available from FFmpeg process");
632+
}
609633
}
610634
});
611635

0 commit comments

Comments
 (0)