mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 19:31:35 +00:00
Remove fancy span following code
This commit is contained in:
parent
a47f2a3428
commit
11739cd42c
5 changed files with 18 additions and 54 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1347,7 +1347,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "pict-rs"
|
||||
version = "0.3.0-beta.8"
|
||||
version = "0.3.0-beta.9"
|
||||
dependencies = [
|
||||
"actix-form-data",
|
||||
"actix-rt",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "pict-rs"
|
||||
description = "A simple image hosting service"
|
||||
version = "0.3.0-beta.8"
|
||||
version = "0.3.0-beta.9"
|
||||
authors = ["asonix <asonix@asonix.dog>"]
|
||||
license = "AGPL-3.0"
|
||||
readme = "README.md"
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
use tracing::{Id, Span};
|
||||
|
||||
pub(crate) enum IdOrSpan {
|
||||
Id(Option<Id>),
|
||||
Span(Span),
|
||||
}
|
||||
|
||||
impl IdOrSpan {
|
||||
pub(crate) fn take(&mut self) -> Self {
|
||||
std::mem::replace(self, IdOrSpan::Id(None))
|
||||
}
|
||||
|
||||
pub(crate) fn from_id(id: Option<Id>) -> Self {
|
||||
IdOrSpan::Id(id)
|
||||
}
|
||||
|
||||
fn span(&self) -> Option<&Span> {
|
||||
match self {
|
||||
IdOrSpan::Span(ref span) => Some(span),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn as_span(&mut self, f: impl Fn(Option<Id>) -> Span) -> &Span {
|
||||
let span = match self.take() {
|
||||
Self::Id(opt) => f(opt),
|
||||
Self::Span(span) => span,
|
||||
};
|
||||
|
||||
*self = Self::Span(span);
|
||||
|
||||
self.span().expect("Span should always exist")
|
||||
}
|
||||
}
|
|
@ -31,7 +31,6 @@ mod error;
|
|||
mod exiftool;
|
||||
mod ffmpeg;
|
||||
mod file;
|
||||
mod id_or_span;
|
||||
mod init_tracing;
|
||||
mod magick;
|
||||
mod map_error;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{id_or_span::IdOrSpan, store::Store};
|
||||
use crate::store::Store;
|
||||
use actix_rt::task::JoinHandle;
|
||||
use actix_web::web::Bytes;
|
||||
use std::{
|
||||
|
@ -13,14 +13,14 @@ use tokio::{
|
|||
sync::oneshot::{channel, Receiver},
|
||||
};
|
||||
use tracing::Instrument;
|
||||
use tracing::{Id, Span};
|
||||
use tracing::Span;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct StatusError;
|
||||
|
||||
pub(crate) struct Process {
|
||||
child: Child,
|
||||
id: Option<Id>,
|
||||
span: Span,
|
||||
}
|
||||
|
||||
struct DropHandle {
|
||||
|
@ -31,7 +31,7 @@ pin_project_lite::pin_project! {
|
|||
struct ProcessRead<I> {
|
||||
#[pin]
|
||||
inner: I,
|
||||
span: IdOrSpan,
|
||||
span: Span,
|
||||
err_recv: Receiver<std::io::Error>,
|
||||
err_closed: bool,
|
||||
handle: DropHandle,
|
||||
|
@ -45,9 +45,7 @@ impl Process {
|
|||
|
||||
fn spawn_span(&self) -> Span {
|
||||
let span = tracing::info_span!(parent: None, "Spawned command writer",);
|
||||
|
||||
span.follows_from(self.id.clone());
|
||||
|
||||
span.follows_from(self.span.clone());
|
||||
span
|
||||
}
|
||||
|
||||
|
@ -57,7 +55,7 @@ impl Process {
|
|||
|
||||
cmd.spawn().map(|child| Process {
|
||||
child,
|
||||
id: Span::current().id(),
|
||||
span: Span::current(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -102,7 +100,7 @@ impl Process {
|
|||
|
||||
Some(ProcessRead {
|
||||
inner: stdout,
|
||||
span: IdOrSpan::from_id(self.id),
|
||||
span: body_span(self.span),
|
||||
err_recv: rx,
|
||||
err_closed: false,
|
||||
handle: DropHandle { inner: handle },
|
||||
|
@ -135,7 +133,7 @@ impl Process {
|
|||
|
||||
Some(ProcessRead {
|
||||
inner: stdout,
|
||||
span: IdOrSpan::from_id(self.id),
|
||||
span: body_span(self.span),
|
||||
err_recv: rx,
|
||||
err_closed: false,
|
||||
handle: DropHandle { inner: handle },
|
||||
|
@ -179,7 +177,7 @@ impl Process {
|
|||
|
||||
Some(ProcessRead {
|
||||
inner: stdout,
|
||||
span: IdOrSpan::from_id(self.id),
|
||||
span: body_span(self.span),
|
||||
err_recv: rx,
|
||||
err_closed: false,
|
||||
handle: DropHandle { inner: handle },
|
||||
|
@ -187,6 +185,12 @@ impl Process {
|
|||
}
|
||||
}
|
||||
|
||||
fn body_span(following: Span) -> Span {
|
||||
let span = tracing::info_span!(parent: None, "Processing Command");
|
||||
span.follows_from(following);
|
||||
span
|
||||
}
|
||||
|
||||
impl<I> AsyncRead for ProcessRead<I>
|
||||
where
|
||||
I: AsyncRead,
|
||||
|
@ -201,12 +205,7 @@ where
|
|||
let err_recv = this.err_recv;
|
||||
let err_closed = this.err_closed;
|
||||
let inner = this.inner;
|
||||
|
||||
let span = this.span.as_span(|id| {
|
||||
let span = tracing::info_span!("Processing Command");
|
||||
span.follows_from(id);
|
||||
span
|
||||
});
|
||||
let span = this.span;
|
||||
|
||||
span.in_scope(|| {
|
||||
if !*err_closed {
|
||||
|
|
Loading…
Reference in a new issue