-
Notifications
You must be signed in to change notification settings - Fork 4
Pause sample env topic between runs #336
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
Merged
DanNixon
merged 10 commits into
ISISNeutronMuon:main
from
Modularius:Pause-sample-env-topic-between-runs
May 3, 2025
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
53d22b4
Introduced TopicSubscriber
Modularius 562fed3
Change to common crate, and trivial changes to other crates
Modularius 68ddd0e
Add Kafka Error variant
Modularius f27e951
Kafka dependency type
Modularius bab18c5
Introduced NexusEngineDependencies so that further dependencies can b…
Modularius 5687034
Formatting and comments
Modularius b2f350f
Changed error handling of create_default_consumer
Modularius 9fba2f6
Simplify kafka topic interface
Modularius ca0a9de
Merge branch 'main' into Pause-sample-env-topic-between-runs
Modularius 705ec8d
Method name change
Modularius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| use rdkafka::{ | ||
| consumer::{Consumer, StreamConsumer}, | ||
| error::KafkaResult, | ||
| }; | ||
| use tracing::debug; | ||
|
|
||
| pub(crate) trait KafkaTopicInterface { | ||
| fn ensure_subscription_mode_is(&mut self, mode: TopicMode) -> KafkaResult<()>; | ||
| } | ||
|
|
||
| pub(super) struct Topics { | ||
| pub(super) control: String, | ||
| pub(super) log: String, | ||
| pub(super) frame_event: String, | ||
| pub(super) sample_env: String, | ||
| pub(super) alarm: String, | ||
| } | ||
|
|
||
| fn get_nonrepeating_list(list: Vec<&str>) -> Vec<&str> { | ||
Modularius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let mut topics_to_subscribe = list.into_iter().collect::<Vec<&str>>(); | ||
Modularius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| debug!("{topics_to_subscribe:?}"); | ||
| topics_to_subscribe.sort(); | ||
| topics_to_subscribe.dedup(); | ||
| topics_to_subscribe | ||
| } | ||
|
|
||
| impl Topics { | ||
| fn get_full_nonrepeating_list(&self) -> Vec<&str> { | ||
Modularius marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| get_nonrepeating_list(vec![ | ||
| &self.control, | ||
| &self.log, | ||
| &self.frame_event, | ||
| &self.sample_env, | ||
| &self.alarm, | ||
| ]) | ||
| } | ||
|
|
||
| fn get_continuous_only_nonrepeating_list(&self) -> Vec<&str> { | ||
| get_nonrepeating_list(vec![&self.control, &self.log, &self.frame_event]) | ||
| } | ||
| } | ||
|
|
||
| #[derive(PartialEq)] | ||
| pub(crate) enum TopicMode { | ||
| Full, | ||
| ConitinousOnly, | ||
| } | ||
|
|
||
| pub(crate) struct TopicSubscriber<'a> { | ||
| mode: Option<TopicMode>, | ||
| consumer: &'a StreamConsumer, | ||
| full_list: Vec<&'a str>, | ||
| continous_only_list: Vec<&'a str>, | ||
| } | ||
|
|
||
| impl<'a> TopicSubscriber<'a> { | ||
| pub(crate) fn new(consumer: &'a StreamConsumer, topics: &'a Topics) -> Self { | ||
| let full_list = topics.get_full_nonrepeating_list(); | ||
| let continous_only_list = topics.get_continuous_only_nonrepeating_list(); | ||
| Self { | ||
| mode: None, | ||
| consumer, | ||
| full_list, | ||
| continous_only_list, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl KafkaTopicInterface for TopicSubscriber<'_> { | ||
| fn ensure_subscription_mode_is(&mut self, mode: TopicMode) -> KafkaResult<()> { | ||
| if self | ||
| .mode | ||
| .as_ref() | ||
| .is_none_or(|this_mode| this_mode.eq(&mode)) | ||
| { | ||
| if self.mode.is_some() { | ||
| self.consumer.unsubscribe(); | ||
| } | ||
| match mode { | ||
| TopicMode::Full => self.consumer.subscribe(&self.full_list)?, | ||
| TopicMode::ConitinousOnly => self.consumer.subscribe(&self.continous_only_list)?, | ||
| }; | ||
Modularius marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.mode = Some(mode); | ||
| } | ||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| pub(crate) struct NoKafka; | ||
|
|
||
| #[cfg(test)] | ||
| impl KafkaTopicInterface for NoKafka { | ||
| fn ensure_subscription_mode_is(&mut self, _mode: TopicMode) -> KafkaResult<()> { | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.