From d7e401eeed7b5069357d8ce759e0bd621382c09a Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 3 Jun 2022 12:37:57 +0200 Subject: [PATCH] Set worker count 0 in debug mode --- examples/federation/instance.rs | 5 +---- src/core/activity_queue.rs | 12 ++++++++++-- src/lib.rs | 6 +----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/federation/instance.rs b/examples/federation/instance.rs index 207ad4d..9c1394d 100644 --- a/examples/federation/instance.rs +++ b/examples/federation/instance.rs @@ -39,10 +39,7 @@ pub struct Instance { impl Instance { pub fn new(hostname: String) -> Result { - let settings = InstanceSettingsBuilder::default() - .debug(true) - .worker_count(1) - .build()?; + let settings = InstanceSettingsBuilder::default().debug(true).build()?; let local_instance = LocalInstance::new(hostname.clone(), Client::default().into(), settings); let local_user = MyUser::new(generate_object_id(&hostname)?, generate_actor_keypair()?); diff --git a/src/core/activity_queue.rs b/src/core/activity_queue.rs index 749c7a4..0e3a497 100644 --- a/src/core/activity_queue.rs +++ b/src/core/activity_queue.rs @@ -2,6 +2,7 @@ use crate::{ core::signatures::{sign_request, PublicKey}, utils::verify_url_valid, Error, + InstanceSettings, LocalInstance, APUB_JSON_CONTENT_TYPE, }; @@ -181,9 +182,16 @@ fn generate_request_headers(inbox_url: &Url) -> HeaderMap { pub(crate) fn create_activity_queue( client: ClientWithMiddleware, - worker_count: u64, - timeout: Duration, + settings: &InstanceSettings, ) -> Manager { + // queue is not used in debug mod, so dont create any workers to avoid log spam + let worker_count = if settings.debug { + 0 + } else { + settings.worker_count + }; + let timeout = settings.request_timeout; + // Configure and start our workers WorkerConfig::new_managed(Storage::new(), move |_| MyState { client: client.clone(), diff --git a/src/lib.rs b/src/lib.rs index ffcace2..2b6fb3b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -51,11 +51,7 @@ pub struct InstanceSettings { impl LocalInstance { pub fn new(domain: String, client: ClientWithMiddleware, settings: InstanceSettings) -> Self { - let activity_queue = create_activity_queue( - client.clone(), - settings.worker_count, - settings.request_timeout, - ); + let activity_queue = create_activity_queue(client.clone(), &settings); LocalInstance { hostname: domain, client,