📦 ♻️ Refactor a bunch of stuff; debian packaging
This commit is contained in:
parent
a0091235a4
commit
a67a677a1a
15 changed files with 1119 additions and 149 deletions
43
src/generic.rs
Normal file
43
src/generic.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
use crate::process::{ProcessEvent, ProcessHandler};
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::{Instrument, Span};
|
||||
|
||||
pub fn run_executable(
|
||||
token: CancellationToken,
|
||||
span: Span,
|
||||
executable: &'static str,
|
||||
args: Vec<String>,
|
||||
env_vars: Vec<(String, String)>,
|
||||
) {
|
||||
let span_2 = span.clone();
|
||||
let (tx, mut rx) = unbounded_channel::<ProcessEvent>();
|
||||
tokio::spawn(
|
||||
async move {
|
||||
ProcessHandler::new(tx, &token).run(executable, args, env_vars, &span);
|
||||
while let Some(event) = rx.recv().await {
|
||||
match event {
|
||||
ProcessEvent::Started => {
|
||||
info!("started");
|
||||
}
|
||||
ProcessEvent::Stdout(line) => {
|
||||
info!("{}", line);
|
||||
}
|
||||
ProcessEvent::Stderr(line) => {
|
||||
error!("{}", line);
|
||||
}
|
||||
ProcessEvent::Ended(Some(status)) => {
|
||||
error!("exited with status {}", status);
|
||||
return;
|
||||
}
|
||||
ProcessEvent::Ended(None) => {
|
||||
error!("exited");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.instrument(span_2),
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue