From bb1880478d9f345b6c51769c880cdb688c32e1ff Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Wed, 28 Oct 2020 13:28:46 +0100 Subject: [PATCH] ref(envelopes): Refactor EventProcessor ctor for ease of testing This is split out from #823. --- relay-server/src/actors/events.rs | 37 ++++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/relay-server/src/actors/events.rs b/relay-server/src/actors/events.rs index eb0d3865d1..0412a80e14 100644 --- a/relay-server/src/actors/events.rs +++ b/relay-server/src/actors/events.rs @@ -269,22 +269,29 @@ pub struct EventProcessor { } impl EventProcessor { - #[cfg(feature = "processing")] - pub fn new( - config: Arc, - rate_limiter: Option, - geoip_lookup: Option>, - ) -> Self { + #[inline] + pub fn new(config: Arc) -> Self { Self { config, - rate_limiter, - geoip_lookup, + #[cfg(feature = "processing")] + rate_limiter: None, + #[cfg(feature = "processing")] + geoip_lookup: None, } } - #[cfg(not(feature = "processing"))] - pub fn new(config: Arc) -> Self { - Self { config } + #[cfg(feature = "processing")] + #[inline] + pub fn with_rate_limiter(mut self, rate_limiter: Option) -> Self { + self.rate_limiter = rate_limiter; + self + } + + #[cfg(feature = "processing")] + #[inline] + pub fn with_geoip_lookup(mut self, geoip_lookup: Option>) -> Self { + self.geoip_lookup = geoip_lookup; + self } /// Validates all sessions in the envelope, if any. @@ -1229,11 +1236,9 @@ impl EventManager { SyncArbiter::start( thread_count, - clone!(config, || EventProcessor::new( - config.clone(), - rate_limiter.clone(), - geoip_lookup.clone(), - )), + clone!(config, || EventProcessor::new(config.clone()) + .with_rate_limiter(rate_limiter.clone()) + .with_geoip_lookup(geoip_lookup.clone())), ) };