background-jobs-example: reomve ClientFactoryBuilder, borrow more in AwcClient
This commit is contained in:
parent
ca8adac329
commit
5bcbcebb24
|
@ -1,6 +1,6 @@
|
|||
use actix_rt::Arbiter;
|
||||
use apub_awc::{AwcClient, SignatureConfig};
|
||||
use apub_background_jobs::{client, ClientFactoryBuilder, DeliverJob};
|
||||
use apub_background_jobs::{client, DeliverJob};
|
||||
use apub_breaker_session::BreakerSession;
|
||||
use apub_core::{deliver::Activity, session::RequestCountSession};
|
||||
use apub_rustcrypto::Rustcrypto;
|
||||
|
@ -16,35 +16,16 @@ struct State {
|
|||
client: awc::Client,
|
||||
}
|
||||
|
||||
struct ClientFactory {
|
||||
config: SignatureConfig,
|
||||
session: (RequestCountSession, BreakerSession),
|
||||
client: awc::Client,
|
||||
}
|
||||
|
||||
impl ClientFactoryBuilder for State {
|
||||
impl<'a> apub_background_jobs::ClientFactory<'a> for State {
|
||||
type Crypto = Rustcrypto;
|
||||
type ClientFactory = ClientFactory;
|
||||
|
||||
fn build(&self) -> Self::ClientFactory {
|
||||
ClientFactory {
|
||||
config: self.config.clone(),
|
||||
session: (RequestCountSession::max(30), self.breakers.clone()),
|
||||
client: self.client.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> apub_background_jobs::ClientFactory<'a> for ClientFactory {
|
||||
type Crypto = Rustcrypto;
|
||||
type Client = AwcClient<'a, (RequestCountSession, BreakerSession), Self::Crypto>;
|
||||
type Client = AwcClient<'a, (RequestCountSession, &'a BreakerSession), &'a Rustcrypto>;
|
||||
|
||||
fn client(&'a self, crypto: &'a Self::Crypto) -> Self::Client {
|
||||
AwcClient::new(
|
||||
&self.client,
|
||||
&self.session,
|
||||
(RequestCountSession::max(25), &self.breakers),
|
||||
self.config.clone(),
|
||||
crypto.clone(),
|
||||
crypto,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
breakers: breakers.clone(),
|
||||
client: awc::Client::new(),
|
||||
})
|
||||
.register::<DeliverJob<State>>()
|
||||
.register::<DeliverJob<State, Rustcrypto>>()
|
||||
.start_in_arbiter(&arbiter, queue_handle.clone());
|
||||
|
||||
let private_key = RsaPrivateKey::new(&mut rand::thread_rng(), 1024)?;
|
||||
|
@ -83,7 +64,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
kind: NoteType::Note,
|
||||
content: String::from("hi"),
|
||||
};
|
||||
note.deliver(&inbox, &client::<State>(crypto, queue_handle.clone()))
|
||||
note.deliver(&inbox, &client::<State, _>(crypto, queue_handle.clone()))
|
||||
.await?;
|
||||
|
||||
actix_rt::signal::ctrl_c().await?;
|
||||
|
|
Loading…
Reference in a new issue