mirror of
https://git.asonix.dog/asonix/background-jobs.git
synced 2024-11-22 03:51:00 +00:00
Remove lingering .enter calls
This commit is contained in:
parent
ba60a5cbe0
commit
68a80085de
4 changed files with 52 additions and 55 deletions
|
@ -119,6 +119,6 @@ impl Job for PanickingJob {
|
||||||
const MAX_RETRIES: MaxRetries = MaxRetries::Count(0);
|
const MAX_RETRIES: MaxRetries = MaxRetries::Count(0);
|
||||||
|
|
||||||
fn run(self, _: MyState) -> Self::Future {
|
fn run(self, _: MyState) -> Self::Future {
|
||||||
panic!("A panicking job does not stop others from running")
|
panic!("boom")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ pub(crate) fn local_worker<State>(
|
||||||
let id = Uuid::new_v4();
|
let id = Uuid::new_v4();
|
||||||
|
|
||||||
let span = tracing::info_span!(
|
let span = tracing::info_span!(
|
||||||
parent: None,
|
|
||||||
"Worker",
|
"Worker",
|
||||||
worker.id = tracing::field::display(&id),
|
worker.id = tracing::field::display(&id),
|
||||||
worker.queue = tracing::field::display(&queue),
|
worker.queue = tracing::field::display(&queue),
|
||||||
|
|
|
@ -107,20 +107,17 @@ where
|
||||||
fn run(self, state: Self::State) -> Self::Future {
|
fn run(self, state: Self::State) -> Self::Future {
|
||||||
let (tx, rx) = oneshot::channel();
|
let (tx, rx) = oneshot::channel();
|
||||||
|
|
||||||
let span = Span::current();
|
let fut = ActixJob::run(self, state);
|
||||||
let handle = actix_rt::spawn(async move {
|
let handle = actix_rt::spawn(
|
||||||
let entered = span.enter();
|
async move {
|
||||||
let fut = ActixJob::run(self, state);
|
let result = fut.await;
|
||||||
drop(entered);
|
|
||||||
|
|
||||||
let result = fut.instrument(span.clone()).await;
|
if tx.send(result).is_err() {
|
||||||
|
error!("Job dropped");
|
||||||
if tx.send(result).is_err() {
|
}
|
||||||
let entered = span.enter();
|
|
||||||
error!("Job dropped");
|
|
||||||
drop(entered);
|
|
||||||
}
|
}
|
||||||
});
|
.instrument(Span::current()),
|
||||||
|
);
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
handle.await.unwrap();
|
handle.await.unwrap();
|
||||||
|
|
|
@ -79,31 +79,33 @@ where
|
||||||
/// intended for internal use.
|
/// intended for internal use.
|
||||||
pub async fn process(&self, job: JobInfo) -> ReturnJobInfo {
|
pub async fn process(&self, job: JobInfo) -> ReturnJobInfo {
|
||||||
let span = job_span(&job);
|
let span = job_span(&job);
|
||||||
let opt = self.inner.get(job.name()).map(|name| {
|
|
||||||
let entered = span.enter();
|
|
||||||
let fut = process(Arc::clone(name), (self.state_fn)(), job.clone());
|
|
||||||
drop(entered);
|
|
||||||
fut
|
|
||||||
});
|
|
||||||
|
|
||||||
let res = if let Some(fut) = opt {
|
let fut = async move {
|
||||||
fut.instrument(span.clone()).await
|
let opt = self
|
||||||
} else {
|
.inner
|
||||||
span.record(
|
.get(job.name())
|
||||||
"exception.message",
|
.map(|name| process(Arc::clone(name), (self.state_fn)(), job.clone()));
|
||||||
&tracing::field::display("Not registered"),
|
|
||||||
);
|
let res = if let Some(fut) = opt {
|
||||||
span.record(
|
fut.await
|
||||||
"exception.details",
|
} else {
|
||||||
&tracing::field::display("Not registered"),
|
let span = Span::current();
|
||||||
);
|
span.record(
|
||||||
let entered = span.enter();
|
"exception.message",
|
||||||
error!("Not registered");
|
&tracing::field::display("Not registered"),
|
||||||
drop(entered);
|
);
|
||||||
ReturnJobInfo::unregistered(job.id())
|
span.record(
|
||||||
|
"exception.details",
|
||||||
|
&tracing::field::display("Not registered"),
|
||||||
|
);
|
||||||
|
error!("Not registered");
|
||||||
|
ReturnJobInfo::unregistered(job.id())
|
||||||
|
};
|
||||||
|
|
||||||
|
res
|
||||||
};
|
};
|
||||||
|
|
||||||
res
|
fut.instrument(span).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,28 +120,27 @@ where
|
||||||
pub async fn process(&self, job: JobInfo) -> ReturnJobInfo {
|
pub async fn process(&self, job: JobInfo) -> ReturnJobInfo {
|
||||||
let span = job_span(&job);
|
let span = job_span(&job);
|
||||||
|
|
||||||
let res = if let Some(name) = self.inner.get(job.name()) {
|
let fut = async move {
|
||||||
let entered = span.enter();
|
let res = if let Some(name) = self.inner.get(job.name()) {
|
||||||
let fut = process(Arc::clone(name), self.state.clone(), job);
|
process(Arc::clone(name), self.state.clone(), job).await
|
||||||
drop(entered);
|
} else {
|
||||||
|
let span = Span::current();
|
||||||
|
span.record(
|
||||||
|
"exception.message",
|
||||||
|
&tracing::field::display("Not registered"),
|
||||||
|
);
|
||||||
|
span.record(
|
||||||
|
"exception.details",
|
||||||
|
&tracing::field::display("Not registered"),
|
||||||
|
);
|
||||||
|
error!("Not registered");
|
||||||
|
ReturnJobInfo::unregistered(job.id())
|
||||||
|
};
|
||||||
|
|
||||||
fut.instrument(span.clone()).await
|
res
|
||||||
} else {
|
|
||||||
let entered = span.enter();
|
|
||||||
span.record(
|
|
||||||
"exception.message",
|
|
||||||
&tracing::field::display("Not registered"),
|
|
||||||
);
|
|
||||||
span.record(
|
|
||||||
"exception.details",
|
|
||||||
&tracing::field::display("Not registered"),
|
|
||||||
);
|
|
||||||
error!("Not registered");
|
|
||||||
drop(entered);
|
|
||||||
ReturnJobInfo::unregistered(job.id())
|
|
||||||
};
|
};
|
||||||
|
|
||||||
res
|
fut.instrument(span).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue