mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-23 03:41:23 +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]]
|
[[package]]
|
||||||
name = "pict-rs"
|
name = "pict-rs"
|
||||||
version = "0.3.0-beta.8"
|
version = "0.3.0-beta.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-form-data",
|
"actix-form-data",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "pict-rs"
|
name = "pict-rs"
|
||||||
description = "A simple image hosting service"
|
description = "A simple image hosting service"
|
||||||
version = "0.3.0-beta.8"
|
version = "0.3.0-beta.9"
|
||||||
authors = ["asonix <asonix@asonix.dog>"]
|
authors = ["asonix <asonix@asonix.dog>"]
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
readme = "README.md"
|
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 exiftool;
|
||||||
mod ffmpeg;
|
mod ffmpeg;
|
||||||
mod file;
|
mod file;
|
||||||
mod id_or_span;
|
|
||||||
mod init_tracing;
|
mod init_tracing;
|
||||||
mod magick;
|
mod magick;
|
||||||
mod map_error;
|
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_rt::task::JoinHandle;
|
||||||
use actix_web::web::Bytes;
|
use actix_web::web::Bytes;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -13,14 +13,14 @@ use tokio::{
|
||||||
sync::oneshot::{channel, Receiver},
|
sync::oneshot::{channel, Receiver},
|
||||||
};
|
};
|
||||||
use tracing::Instrument;
|
use tracing::Instrument;
|
||||||
use tracing::{Id, Span};
|
use tracing::Span;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct StatusError;
|
struct StatusError;
|
||||||
|
|
||||||
pub(crate) struct Process {
|
pub(crate) struct Process {
|
||||||
child: Child,
|
child: Child,
|
||||||
id: Option<Id>,
|
span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DropHandle {
|
struct DropHandle {
|
||||||
|
@ -31,7 +31,7 @@ pin_project_lite::pin_project! {
|
||||||
struct ProcessRead<I> {
|
struct ProcessRead<I> {
|
||||||
#[pin]
|
#[pin]
|
||||||
inner: I,
|
inner: I,
|
||||||
span: IdOrSpan,
|
span: Span,
|
||||||
err_recv: Receiver<std::io::Error>,
|
err_recv: Receiver<std::io::Error>,
|
||||||
err_closed: bool,
|
err_closed: bool,
|
||||||
handle: DropHandle,
|
handle: DropHandle,
|
||||||
|
@ -45,9 +45,7 @@ impl Process {
|
||||||
|
|
||||||
fn spawn_span(&self) -> Span {
|
fn spawn_span(&self) -> Span {
|
||||||
let span = tracing::info_span!(parent: None, "Spawned command writer",);
|
let span = tracing::info_span!(parent: None, "Spawned command writer",);
|
||||||
|
span.follows_from(self.span.clone());
|
||||||
span.follows_from(self.id.clone());
|
|
||||||
|
|
||||||
span
|
span
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +55,7 @@ impl Process {
|
||||||
|
|
||||||
cmd.spawn().map(|child| Process {
|
cmd.spawn().map(|child| Process {
|
||||||
child,
|
child,
|
||||||
id: Span::current().id(),
|
span: Span::current(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +100,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: IdOrSpan::from_id(self.id),
|
span: body_span(self.span),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
handle: DropHandle { inner: handle },
|
||||||
|
@ -135,7 +133,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: IdOrSpan::from_id(self.id),
|
span: body_span(self.span),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
handle: DropHandle { inner: handle },
|
||||||
|
@ -179,7 +177,7 @@ impl Process {
|
||||||
|
|
||||||
Some(ProcessRead {
|
Some(ProcessRead {
|
||||||
inner: stdout,
|
inner: stdout,
|
||||||
span: IdOrSpan::from_id(self.id),
|
span: body_span(self.span),
|
||||||
err_recv: rx,
|
err_recv: rx,
|
||||||
err_closed: false,
|
err_closed: false,
|
||||||
handle: DropHandle { inner: handle },
|
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>
|
impl<I> AsyncRead for ProcessRead<I>
|
||||||
where
|
where
|
||||||
I: AsyncRead,
|
I: AsyncRead,
|
||||||
|
@ -201,12 +205,7 @@ where
|
||||||
let err_recv = this.err_recv;
|
let err_recv = this.err_recv;
|
||||||
let err_closed = this.err_closed;
|
let err_closed = this.err_closed;
|
||||||
let inner = this.inner;
|
let inner = this.inner;
|
||||||
|
let span = this.span;
|
||||||
let span = this.span.as_span(|id| {
|
|
||||||
let span = tracing::info_span!("Processing Command");
|
|
||||||
span.follows_from(id);
|
|
||||||
span
|
|
||||||
});
|
|
||||||
|
|
||||||
span.in_scope(|| {
|
span.in_scope(|| {
|
||||||
if !*err_closed {
|
if !*err_closed {
|
||||||
|
|
Loading…
Reference in a new issue