📦 ♻️ Refactor a bunch of stuff; debian packaging

This commit is contained in:
Lucy 2022-07-07 16:45:17 -04:00
parent a0091235a4
commit a67a677a1a
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
15 changed files with 1119 additions and 149 deletions

43
src/generic.rs Normal file
View 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),
);
}