Skip to content

Commit f647b87

Browse files
committed
worker/background_job: Return BoxFuture to avoid lifetime issues
1 parent a603713 commit f647b87

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

crates/crates_io_worker/src/background_job.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ use diesel::dsl::{exists, not};
44
use diesel::sql_types::{Int2, Jsonb, Text};
55
use diesel::{ExpressionMethods, IntoSql, OptionalExtension, QueryDsl};
66
use diesel_async::{AsyncPgConnection, RunQueryDsl};
7-
use futures_util::future::BoxFuture;
87
use futures_util::FutureExt;
9-
use serde::de::DeserializeOwned;
8+
use futures_util::future::BoxFuture;
109
use serde::Serialize;
10+
use serde::de::DeserializeOwned;
1111
use serde_json::Value;
1212
use std::future::Future;
1313
use tracing::instrument;
@@ -61,12 +61,12 @@ pub trait BackgroundJob: Serialize + DeserializeOwned + Send + Sync + 'static {
6161
}
6262
}
6363

64-
fn enqueue_deduplicated(
64+
fn enqueue_deduplicated<'a>(
6565
conn: &mut AsyncPgConnection,
66-
job_type: &'static str,
66+
job_type: &'a str,
6767
data: Value,
6868
priority: i16,
69-
) -> impl Future<Output = Result<Option<i64>, EnqueueError>> {
69+
) -> BoxFuture<'a, Result<Option<i64>, EnqueueError>> {
7070
let similar_jobs = background_jobs::table
7171
.select(background_jobs::id)
7272
.filter(background_jobs::job_type.eq(job_type))
@@ -92,15 +92,15 @@ fn enqueue_deduplicated(
9292
.returning(background_jobs::id)
9393
.get_result::<i64>(conn);
9494

95-
async move { Ok(future.await.optional()?) }
95+
async move { Ok(future.await.optional()?) }.boxed()
9696
}
9797

98-
fn enqueue_simple(
98+
fn enqueue_simple<'a>(
9999
conn: &mut AsyncPgConnection,
100-
job_type: &'static str,
100+
job_type: &'a str,
101101
data: Value,
102102
priority: i16,
103-
) -> impl Future<Output = Result<i64, EnqueueError>> {
103+
) -> BoxFuture<'a, Result<i64, EnqueueError>> {
104104
let future = diesel::insert_into(background_jobs::table)
105105
.values((
106106
background_jobs::job_type.eq(job_type),
@@ -110,5 +110,5 @@ fn enqueue_simple(
110110
.returning(background_jobs::id)
111111
.get_result(conn);
112112

113-
async move { Ok(future.await?) }
113+
async move { Ok(future.await?) }.boxed()
114114
}

0 commit comments

Comments
 (0)