mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-11-10 06:25:00 +00:00
Add follows-from relation for background tasks
This commit is contained in:
parent
e493e90dd4
commit
8781bc8f28
1 changed files with 70 additions and 40 deletions
|
@ -12,6 +12,7 @@ use tokio::{
|
||||||
process::{Child, Command},
|
process::{Child, Command},
|
||||||
sync::oneshot::{channel, Receiver},
|
sync::oneshot::{channel, Receiver},
|
||||||
};
|
};
|
||||||
|
use tracing::{Instrument, Span};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct StatusError;
|
struct StatusError;
|
||||||
|
@ -73,9 +74,13 @@ impl Process {
|
||||||
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel")
|
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel")
|
||||||
.in_scope(channel::<std::io::Error>);
|
.in_scope(channel::<std::io::Error>);
|
||||||
|
|
||||||
|
let span = tracing::info_span!(parent: None, "Background process task from bytes");
|
||||||
|
span.follows_from(Span::current());
|
||||||
|
|
||||||
let mut child = self.child;
|
let mut child = self.child;
|
||||||
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
||||||
actix_rt::spawn(async move {
|
actix_rt::spawn(
|
||||||
|
async move {
|
||||||
if let Err(e) = stdin.write_all_buf(&mut input).await {
|
if let Err(e) = stdin.write_all_buf(&mut input).await {
|
||||||
let _ = tx.send(e);
|
let _ = tx.send(e);
|
||||||
return;
|
return;
|
||||||
|
@ -85,15 +90,19 @@ impl Process {
|
||||||
match child.wait().await {
|
match child.wait().await {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
let _ = tx
|
let _ = tx.send(std::io::Error::new(
|
||||||
.send(std::io::Error::new(std::io::ErrorKind::Other, &StatusError));
|
std::io::ErrorKind::Other,
|
||||||
|
&StatusError,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = tx.send(e);
|
let _ = tx.send(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
.instrument(span),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
ProcessRead {
|
ProcessRead {
|
||||||
|
@ -110,21 +119,29 @@ impl Process {
|
||||||
|
|
||||||
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel").in_scope(channel);
|
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel").in_scope(channel);
|
||||||
|
|
||||||
|
let span = tracing::info_span!(parent: None, "Background process task");
|
||||||
|
span.follows_from(Span::current());
|
||||||
|
|
||||||
let mut child = self.child;
|
let mut child = self.child;
|
||||||
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
||||||
actix_rt::spawn(async move {
|
actix_rt::spawn(
|
||||||
|
async move {
|
||||||
match child.wait().await {
|
match child.wait().await {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
let _ = tx
|
let _ = tx.send(std::io::Error::new(
|
||||||
.send(std::io::Error::new(std::io::ErrorKind::Other, &StatusError));
|
std::io::ErrorKind::Other,
|
||||||
|
&StatusError,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = tx.send(e);
|
let _ = tx.send(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
.instrument(span),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
ProcessRead {
|
ProcessRead {
|
||||||
|
@ -146,9 +163,18 @@ impl Process {
|
||||||
|
|
||||||
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel").in_scope(channel);
|
let (tx, rx) = tracing::trace_span!(parent: None, "Create channel").in_scope(channel);
|
||||||
|
|
||||||
|
let span = tracing::info_span!(
|
||||||
|
parent: None,
|
||||||
|
"Background processs task from store",
|
||||||
|
?store,
|
||||||
|
?identifier
|
||||||
|
);
|
||||||
|
span.follows_from(Span::current());
|
||||||
|
|
||||||
let mut child = self.child;
|
let mut child = self.child;
|
||||||
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
let handle = tracing::trace_span!(parent: None, "Spawn task").in_scope(|| {
|
||||||
actix_rt::spawn(async move {
|
actix_rt::spawn(
|
||||||
|
async move {
|
||||||
if let Err(e) = store.read_into(&identifier, &mut stdin).await {
|
if let Err(e) = store.read_into(&identifier, &mut stdin).await {
|
||||||
let _ = tx.send(e);
|
let _ = tx.send(e);
|
||||||
return;
|
return;
|
||||||
|
@ -158,15 +184,19 @@ impl Process {
|
||||||
match child.wait().await {
|
match child.wait().await {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
let _ = tx
|
let _ = tx.send(std::io::Error::new(
|
||||||
.send(std::io::Error::new(std::io::ErrorKind::Other, &StatusError));
|
std::io::ErrorKind::Other,
|
||||||
|
&StatusError,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let _ = tx.send(e);
|
let _ = tx.send(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
.instrument(span),
|
||||||
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
ProcessRead {
|
ProcessRead {
|
||||||
|
|
Loading…
Reference in a new issue