cleanup and fix child wait, check if ingest got input, console log with timestamp
This commit is contained in:
parent
da2fdd2d75
commit
1b6b9a19aa
@ -224,39 +224,31 @@ impl ChannelManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run_wait(
|
||||||
|
&self,
|
||||||
|
unit: ProcessUnit,
|
||||||
|
child: &Arc<Mutex<Option<Child>>>,
|
||||||
|
) -> Result<(), ProcessError> {
|
||||||
|
if let Some(proc) = child.lock().unwrap().as_mut() {
|
||||||
|
loop {
|
||||||
|
match proc.try_wait() {
|
||||||
|
Ok(Some(_)) => break,
|
||||||
|
Ok(None) => thread::sleep(Duration::from_millis(10)),
|
||||||
|
Err(e) => return Err(ProcessError::Custom(format!("{unit}: {e}"))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Wait for process to proper close.
|
/// Wait for process to proper close.
|
||||||
/// This prevents orphaned/zombi processes in system
|
/// This prevents orphaned/zombi processes in system
|
||||||
pub fn wait(&self, unit: ProcessUnit) -> Result<(), ProcessError> {
|
pub fn wait(&self, unit: ProcessUnit) -> Result<(), ProcessError> {
|
||||||
loop {
|
match unit {
|
||||||
match unit {
|
Decoder => self.run_wait(unit, &self.decoder)?,
|
||||||
Decoder => {
|
Encoder => self.run_wait(unit, &self.encoder)?,
|
||||||
if let Some(proc) = self.decoder.lock().unwrap().as_mut() {
|
Ingest => self.run_wait(unit, &self.ingest)?,
|
||||||
match proc.try_wait() {
|
|
||||||
Ok(Some(_)) => break,
|
|
||||||
Ok(None) => thread::sleep(Duration::from_millis(10)),
|
|
||||||
Err(e) => return Err(ProcessError::Custom(format!("Decoder: {e}"))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Encoder => {
|
|
||||||
if let Some(proc) = self.encoder.lock().unwrap().as_mut() {
|
|
||||||
match proc.try_wait() {
|
|
||||||
Ok(Some(_)) => break,
|
|
||||||
Ok(None) => thread::sleep(Duration::from_millis(10)),
|
|
||||||
Err(e) => return Err(ProcessError::Custom(format!("Encoder: {e}"))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ingest => {
|
|
||||||
if let Some(proc) = self.ingest.lock().unwrap().as_mut() {
|
|
||||||
match proc.try_wait() {
|
|
||||||
Ok(Some(_)) => break,
|
|
||||||
Ok(None) => thread::sleep(Duration::from_millis(10)),
|
|
||||||
Err(e) => return Err(ProcessError::Custom(format!("Ingest: {e}"))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(Duration::from_millis(50));
|
thread::sleep(Duration::from_millis(50));
|
||||||
@ -313,11 +305,6 @@ impl ChannelManager {
|
|||||||
error!(target: Target::all(), channel = channel_id; "{e}")
|
error!(target: Target::all(), channel = channel_id; "{e}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Err(e) = self.wait(unit) {
|
|
||||||
if !e.to_string().contains("exited process") {
|
|
||||||
error!(target: Target::all(), channel = channel_id; "{e}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ fn ingest_to_hls_server(manager: ChannelManager) -> Result<(), ProcessError> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_running {
|
if !is_running && line.contains("Input #0") {
|
||||||
ingest_is_running.store(true, Ordering::SeqCst);
|
ingest_is_running.store(true, Ordering::SeqCst);
|
||||||
playlist_init.store(true, Ordering::SeqCst);
|
playlist_init.store(true, Ordering::SeqCst);
|
||||||
is_running = true;
|
is_running = true;
|
||||||
|
@ -167,7 +167,7 @@ pub struct Args {
|
|||||||
#[clap(long, help_heading = Some("Playlist"), help = "Only validate given playlist")]
|
#[clap(long, help_heading = Some("Playlist"), help = "Only validate given playlist")]
|
||||||
pub validate: bool,
|
pub validate: bool,
|
||||||
|
|
||||||
#[clap(long, env, help_heading = Some("Playout"), help = "Run playout without webserver and frontend.")]
|
#[clap(long, env, help_heading = Some("Playout"), help = "Run playout without webserver and frontend")]
|
||||||
pub foreground: bool,
|
pub foreground: bool,
|
||||||
|
|
||||||
#[clap(short, long, help_heading = Some("Playout"), help = "Play folder content")]
|
#[clap(short, long, help_heading = Some("Playout"), help = "Play folder content")]
|
||||||
@ -176,6 +176,9 @@ pub struct Args {
|
|||||||
#[clap(long, env, help_heading = Some("Playout"), help = "Keep log file for given days")]
|
#[clap(long, env, help_heading = Some("Playout"), help = "Keep log file for given days")]
|
||||||
pub log_backup_count: Option<usize>,
|
pub log_backup_count: Option<usize>,
|
||||||
|
|
||||||
|
#[clap(long, env, help_heading = Some("Playout"), help = "Add timestamp to log line")]
|
||||||
|
pub log_timestamp: bool,
|
||||||
|
|
||||||
#[clap(short, long, help_heading = Some("Playout"), help = "Set output mode: desktop, hls, null, stream")]
|
#[clap(short, long, help_heading = Some("Playout"), help = "Set output mode: desktop, hls, null, stream")]
|
||||||
pub output: Option<OutputMode>,
|
pub output: Option<OutputMode>,
|
||||||
|
|
||||||
|
@ -248,38 +248,32 @@ fn strip_tags(input: &str) -> String {
|
|||||||
re.replace_all(input, "").to_string()
|
re.replace_all(input, "").to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn console_formatter(w: &mut dyn Write, _now: &mut DeferredNow, record: &Record) -> io::Result<()> {
|
fn console_formatter(w: &mut dyn Write, now: &mut DeferredNow, record: &Record) -> io::Result<()> {
|
||||||
match record.level() {
|
let log_line = match record.level() {
|
||||||
Level::Debug => write!(
|
Level::Debug => colorize_string(format!("<bright-blue>[DEBUG]</> {}", record.args())),
|
||||||
|
Level::Error => colorize_string(format!("<bright-red>[ERROR]</> {}", record.args())),
|
||||||
|
Level::Info => colorize_string(format!("<bright-green>[ INFO]</> {}", record.args())),
|
||||||
|
Level::Trace => colorize_string(format!(
|
||||||
|
"<bright-yellow>[TRACE]</> {}:{} {}",
|
||||||
|
record.file().unwrap_or_default(),
|
||||||
|
record.line().unwrap_or_default(),
|
||||||
|
record.args()
|
||||||
|
)),
|
||||||
|
Level::Warn => colorize_string(format!("<yellow>[ WARN]</> {}", record.args())),
|
||||||
|
};
|
||||||
|
|
||||||
|
if ARGS.log_timestamp {
|
||||||
|
write!(
|
||||||
w,
|
w,
|
||||||
"{}",
|
"{} {}",
|
||||||
colorize_string(format!("<bright-blue>[DEBUG]</> {}", record.args()))
|
|
||||||
),
|
|
||||||
Level::Error => write!(
|
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
colorize_string(format!("<bright-red>[ERROR]</> {}", record.args()))
|
|
||||||
),
|
|
||||||
Level::Info => write!(
|
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
colorize_string(format!("<bright-green>[ INFO]</> {}", record.args()))
|
|
||||||
),
|
|
||||||
Level::Trace => write!(
|
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
colorize_string(format!(
|
colorize_string(format!(
|
||||||
"<bright-yellow>[TRACE]</> {}:{} {}",
|
"<bright black>[{}]</>",
|
||||||
record.file().unwrap_or_default(),
|
now.now().format("%Y-%m-%d %H:%M:%S%.6f")
|
||||||
record.line().unwrap_or_default(),
|
)),
|
||||||
record.args()
|
log_line
|
||||||
))
|
)
|
||||||
),
|
} else {
|
||||||
Level::Warn => write!(
|
write!(w, "{}", log_line)
|
||||||
w,
|
|
||||||
"{}",
|
|
||||||
colorize_string(format!("<yellow>[ WARN]</> {}", record.args()))
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user