background-jobs: Bump to background-jobs 0.11

This commit is contained in:
Aode (lion) 2021-11-22 18:53:35 -06:00
parent 3c41d1d719
commit 9bda1acc11
2 changed files with 14 additions and 14 deletions

View file

@ -8,7 +8,7 @@ edition = "2021"
[dependencies] [dependencies]
anyhow = "1" anyhow = "1"
apub-core = { version = "0.1.0", path = "../apub-core/" } apub-core = { version = "0.1.0", path = "../apub-core/" }
background-jobs = "0.9.1" background-jobs = "0.11.0"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
url = { version = "2", features = ["serde"] } url = { version = "2", features = ["serde"] }
@ -17,6 +17,5 @@ url = { version = "2", features = ["serde"] }
actix-rt = "2.5.0" actix-rt = "2.5.0"
apub-reqwest = { version = "0.1.0", path = "../apub-reqwest/" } apub-reqwest = { version = "0.1.0", path = "../apub-reqwest/" }
apub-openssl = { version = "0.1.0", path = "../apub-openssl/" } apub-openssl = { version = "0.1.0", path = "../apub-openssl/" }
background-jobs = "0.9.1"
openssl = "0.10" openssl = "0.10"
reqwest = { version = "0.11", default-features = false } reqwest = { version = "0.11", default-features = false }

View file

@ -55,11 +55,7 @@
use apub_core::{deliver::Client, digest::DigestFactory, signature::SignFactory}; use apub_core::{deliver::Client, digest::DigestFactory, signature::SignFactory};
use background_jobs::{ActixJob, QueueHandle}; use background_jobs::{ActixJob, QueueHandle};
use std::{ use std::{future::Future, marker::PhantomData, pin::Pin};
future::{Future, Ready},
marker::PhantomData,
pin::Pin,
};
use url::Url; use url::Url;
/// A trait describing acquiring an HTTP Client type from Job State and crypto /// A trait describing acquiring an HTTP Client type from Job State and crypto
@ -126,14 +122,16 @@ where
+ DigestFactory + DigestFactory
+ SignFactory + SignFactory
+ Clone + Clone
+ std::panic::UnwindSafe
+ 'static, + 'static,
{ {
/// Enqueue the activity to be delivered, consuming the client /// Enqueue the activity to be delivered, consuming the client
pub fn enqueue<T>(self, inbox: Url, activity: &T) -> Result<(), EnqueueError> pub async fn enqueue<T>(self, inbox: Url, activity: &T) -> Result<(), EnqueueError>
where where
T: serde::ser::Serialize, T: serde::ser::Serialize,
{ {
queue_deliver::<T, State, Crypto>(inbox, activity, self.crypto, &self.handle) queue_deliver::<T, State, Crypto>(inbox, activity, self.crypto, &self.handle)
.await
.map_err(EnqueueError) .map_err(EnqueueError)
} }
} }
@ -158,29 +156,31 @@ where
+ DigestFactory + DigestFactory
+ SignFactory + SignFactory
+ Clone + Clone
+ std::panic::UnwindSafe
+ 'static, + 'static,
{ {
type Error = EnqueueError; type Error = EnqueueError;
type Future = Ready<Result<(), Self::Error>>; type Future = Pin<Box<dyn Future<Output = Result<(), Self::Error>> + 'a>>;
fn deliver<T: serde::ser::Serialize>( fn deliver<T: serde::ser::Serialize>(
&'a self, &'a self,
inbox: &'a Url, inbox: &'a Url,
activity: &'a T, activity: &'a T,
) -> Self::Future { ) -> Self::Future {
std::future::ready( Box::pin(async move {
queue_deliver::<T, State, Crypto>( queue_deliver::<T, State, Crypto>(
inbox.clone(), inbox.clone(),
activity, activity,
self.crypto.clone(), self.crypto.clone(),
&self.handle, &self.handle,
) )
.map_err(EnqueueError), .await
) .map_err(EnqueueError)
})
} }
} }
fn queue_deliver<T, State, Crypto>( async fn queue_deliver<T, State, Crypto>(
inbox: Url, inbox: Url,
activity: &T, activity: &T,
crypto: Crypto, crypto: Crypto,
@ -193,6 +193,7 @@ where
+ serde::ser::Serialize + serde::ser::Serialize
+ DigestFactory + DigestFactory
+ SignFactory + SignFactory
+ std::panic::UnwindSafe
+ 'static, + 'static,
{ {
let job: DeliverJob<State, Crypto> = DeliverJob { let job: DeliverJob<State, Crypto> = DeliverJob {
@ -202,7 +203,7 @@ where
_state: PhantomData, _state: PhantomData,
}; };
handle.queue(job) handle.queue(job).await
} }
impl<State, Crypto> ActixJob for DeliverJob<State, Crypto> impl<State, Crypto> ActixJob for DeliverJob<State, Crypto>