-
Notifications
You must be signed in to change notification settings - Fork 401
feat(background-processor): add BackgroundProcessorBuilder for optional components #3688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(background-processor): add BackgroundProcessorBuilder for optional components #3688
Conversation
👋 I see @wpaulino was un-assigned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already looks pretty good, one question though.
Also, do you have any idea how we could solve the same issue for the async variant of the background processor, i.e., for the optional arguments of process_events_async
?
@@ -1046,6 +1049,171 @@ impl BackgroundProcessor { | |||
None => Ok(()), | |||
} | |||
} | |||
|
|||
/// Creates a new [`BackgroundProcessorBuilder`] to construct a [`BackgroundProcessor`] with optional components. | |||
pub fn builder<'a, PS, EH, M, CM, PGS, RGS, G, UL, L, PM>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused on the purpose of this method: in which scenario would we already have a working BackgroundProcessor
to call builder
on, just to then use the BackgroundProcessorBuilder
to create yet another BackgroundProcessor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing indeed. I was thinking the BackgroundProcessorBuilder::new()
can be an internal method and accessible via builder
, but it doesn't make sense. I will remove the builder
method here and allow users use BackgroundProcessorBuilder::new()
directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tnull this doesn't take self
, though?
Either way, normally the builder pattern has the builder()
associated function, but works something like:
BackgroundProcessor::builder()
constructs a BackgroundProcessorBuilder
with "default" fields (which might be hard in this case), and you would not have any parameters for builder()
.
So yeah, probably removing this is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tnull this doesn't take self, though?
Ah true.
Either way, normally the builder pattern has the
builder()
associated function, but works something like:BackgroundProcessor::builder()
constructs aBackgroundProcessorBuilder
with "default" fields (which might be hard in this case), and you would not have any parameters forbuilder()
.
Yeah, unclear what defaults would be.
👋 The first review has been submitted! Do you think this PR is ready for a second reviewer? If so, click here to assign a second reviewer. |
Yea, I think we can extend the new |
The question is how this would work? What do you think? |
Thank you for the suggestion. I agree that introducing a What do you think about that? |
Sounds good to me, although we might need to account for the fact that the two variants have slightly different type requirements (i.e., trait bounds). But I think we should be able to accommodate that via feature-gates on |
Yes, that can be handled conditionally using feature-gates. I guess I can go ahead with the implementation, right? |
This allows for consistent configuration of sync and async variant of the BackgroundProcessor
This PR is ready for another round of review. |
onion_messenger: Option<OM>, gossip_sync: GossipSync<PGS, RGS, G, UL, L>, peer_manager: PM, | ||
logger: L, scorer: Option<S>, sleeper: Sleeper, mobile_interruptable_platform: bool, | ||
fetch_time: FetchTime, | ||
config: BackgroundProcessorConfig< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we might want to add a #[rustfmt::skip]
here/above to avoid having rustfmt
making this that vertical.
@@ -1048,6 +1160,227 @@ impl BackgroundProcessor { | |||
} | |||
} | |||
|
|||
/// Configuration for both synchronous [`BackgroundProcessor`] and asynchronous [`process_events_async`] event processing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these doc links will work under all circumstances as process_events_async
will only be exposed when the futures
feature is set. You might need to alter the docs based on the set feature via cfg_attr
, see the changes to the background processor docs in #3509 for reference how to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah true! Thank you.
_phantom: PhantomData<(&'a (), CF, T, F, P)>, | ||
} | ||
|
||
/// A builder for constructing a [`BackgroundProcessor`] with optional components. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should say BackgroundProcessorConfig
now, no? And do we want to rename the builder to BackgroundProcessorConfigBuilder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. The builder build
s a BackgroundProcessorConfig
object, so renaming that to BackgroundProcessorConfigBuilder
might be more suitable.
PM::Target: APeerManager + Send + Sync, | ||
{ | ||
/// Creates a new builder instance. | ||
pub(crate) fn new( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems CI is failing due to this being pub(crate)
?
Did another round of review, will take another look once CI passes. |
/// .build(); | ||
/// let bg_processor = BackgroundProcessor::from_config(config); | ||
/// ``` | ||
pub fn from_config< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should even replace start
(i.e., whether we should have start
just take a BackgroundProcessorConfig
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about this too but not sure if we want to make that change on start
immediately.
Thank you very much for the review. I'll address all the feedbacks and update the PR. |
🔔 1st Reminder Hey @dunxen! This PR has been waiting for your review. |
🔔 2nd Reminder Hey @dunxen! This PR has been waiting for your review. |
The builder s and returns a object, so renaming it to seems more suitable.
CI still failing, fixing it. |
This PR introduces two main improvements to the
BackgroundProcessor
:Adds a
BackgroundProcessorBuilder
for a more ergonomic way to construct aBackgroundProcessor
, and supports optional parameters through builder methodsIntroduces
BackgroundProcessorConfig
to standardize configuration across sync (BackgroundProcessor
) and async variants (process_events_async
), enabling same configuration to be used for both variants. The Builder returns this config object, which can be used to construct a processor viaBackgroundProcessor::from_config
Fixes #3612