Skip to content

Commit 9427980

Browse files
Fix rustfmt formatting errors in kafka module and aws module
Applied nightly rustfmt formatting fixes to pass `cargo +nightly fmt --check`: - hydro_test/src/kafka/mod.rs: reorder imports, reformat long lines (consumer creation, flat_map closure, Err match arm, function signatures, function call arguments) - hydro_deploy/core/src/aws.rs: expand struct literal to multi-line format Co-authored-by: Infinity 🤖 <infinity@hydro.run>
1 parent dc7fa2a commit 9427980

6 files changed

Lines changed: 59 additions & 29 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ jobs:
6464
- if: matrix.rust_release == 'latest-stable' && matrix.os == 'ubuntu-latest'
6565
uses: ./.github/actions/use-sccache
6666

67+
- name: Install libcurl dev (needed by rdkafka-sys)
68+
if: runner.os == 'Linux'
69+
run: sudo apt-get update -qq && sudo apt-get install -y -qq libcurl4-openssl-dev > /dev/null
70+
6771
- run: cargo clippy --all-targets -- -D warnings
6872
- run: cargo clippy --all-targets --no-default-features -- -D warnings
6973
- run: cargo clippy --all-targets --all-features -- -D warnings

.github/workflows/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
- name: Install nightly Rust channel
4141
run: rustup toolchain add nightly
4242

43+
- name: Install libcurl dev (needed by rdkafka-sys)
44+
run: sudo apt-get update -qq && sudo apt-get install -y -qq libcurl4-openssl-dev > /dev/null
45+
4346
- env:
4447
RUSTDOCFLAGS: --cfg docsrs -Dwarnings
4548
run: cargo +nightly doc --no-deps --all-features

build_docs.bash

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set -e
22

3+
sudo apt-get update -qq && sudo apt-get install -y -qq libcurl4-openssl-dev > /dev/null
4+
35
echo "========================================="
46
echo "Step 1/7: Downloading LLVM..."
57
echo "========================================="

hydro_deploy/core/src/aws.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ pub struct NetworkResources {
4949

5050
impl NetworkResources {
5151
pub fn new(vpc: String, subnet: String, security_group: String) -> Self {
52-
Self { vpc, subnet, security_group }
52+
Self {
53+
vpc,
54+
subnet,
55+
security_group,
56+
}
5357
}
5458
}
5559

hydro_test/examples/kafka.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
276276
tokio::spawn(async move {
277277
while let Some(_line) = member_out.recv().await {
278278
let t = total.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
279-
if t % 1_000 == 0 {
279+
if t.is_multiple_of(1_000) {
280280
println!("[Consumer {i}] ... {t} total messages consumed so far");
281281
}
282282
if t >= num_messages {

hydro_test/src/kafka/mod.rs

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use hydro_lang::live_collections::boundedness::Boundedness;
22
use hydro_lang::live_collections::stream::{AtLeastOnce, ExactlyOnce, NoOrder, Ordering};
3-
use hydro_lang::location::tick::{NoAtomic, NoTick};
43
use hydro_lang::location::Location;
4+
use hydro_lang::location::tick::{NoAtomic, NoTick};
55
use hydro_lang::prelude::*;
66
use rdkafka::message::OwnedMessage;
77
use rdkafka::producer::BaseProducer;
@@ -72,36 +72,38 @@ where
7272
{
7373
location
7474
.singleton(q!({
75-
let consumer: rdkafka::consumer::StreamConsumer =
76-
rdkafka::config::ClientConfig::new()
77-
.set("bootstrap.servers", brokers)
78-
.set("group.id", group_id)
79-
.set("auto.offset.reset", "earliest")
80-
.set("security.protocol", security_protocol)
81-
.create()
82-
.expect("Failed to create Kafka consumer");
75+
let consumer: rdkafka::consumer::StreamConsumer = rdkafka::config::ClientConfig::new()
76+
.set("bootstrap.servers", brokers)
77+
.set("group.id", group_id)
78+
.set("auto.offset.reset", "earliest")
79+
.set("security.protocol", security_protocol)
80+
.create()
81+
.expect("Failed to create Kafka consumer");
8382
rdkafka::consumer::Consumer::subscribe(&consumer, &[topic])
8483
.expect("Failed to subscribe to topic");
8584
std::sync::Arc::new(consumer)
8685
}))
8786
.into_stream()
88-
.flat_map_stream_blocking(q!(
89-
|consumer: std::sync::Arc<rdkafka::consumer::StreamConsumer>| {
90-
futures_util::stream::unfold(consumer, |consumer| async move {
91-
loop {
92-
match rdkafka::consumer::StreamConsumer::recv(&*consumer).await {
93-
Ok(msg) => {
94-
return Some((rdkafka::message::BorrowedMessage::detach(&msg), consumer));
95-
}
96-
Err(e) => {
97-
eprintln!("Kafka consumer error: {}", e);
98-
continue;
99-
}
87+
.flat_map_stream_blocking(q!(|consumer: std::sync::Arc<
88+
rdkafka::consumer::StreamConsumer,
89+
>| {
90+
futures_util::stream::unfold(consumer, |consumer| async move {
91+
loop {
92+
match rdkafka::consumer::StreamConsumer::recv(&*consumer).await {
93+
Ok(msg) => {
94+
return Some((
95+
rdkafka::message::BorrowedMessage::detach(&msg),
96+
consumer,
97+
));
98+
}
99+
Err(e) => {
100+
eprintln!("Kafka consumer error: {}", e);
101+
continue;
100102
}
101103
}
102-
})
103-
}
104-
))
104+
}
105+
})
106+
}))
105107
.weaken_retries()
106108
.weaken_ordering()
107109
}
@@ -126,7 +128,12 @@ where
126128
.payload(&payload);
127129
match producer.send(record) {
128130
Ok(()) => break,
129-
Err((rdkafka::error::KafkaError::MessageProduction(rdkafka::types::RDKafkaErrorCode::QueueFull), _)) => {
131+
Err((
132+
rdkafka::error::KafkaError::MessageProduction(
133+
rdkafka::types::RDKafkaErrorCode::QueueFull,
134+
),
135+
_,
136+
)) => {
130137
producer.poll(std::time::Duration::from_millis(100));
131138
}
132139
Err((e, _)) => panic!("Failed to send message to Kafka: {}", e),
@@ -157,14 +164,24 @@ pub async fn setup_topic(brokers: &str, topic: &str, num_partitions: i32, securi
157164

158165
/// Blocking version of [`setup_topic`] for use inside synchronous `q!()` blocks.
159166
/// Uses the existing tokio runtime handle from the Hydro process.
160-
pub fn setup_topic_blocking(brokers: &str, topic: &str, num_partitions: i32, security_protocol: &str) {
167+
pub fn setup_topic_blocking(
168+
brokers: &str,
169+
topic: &str,
170+
num_partitions: i32,
171+
security_protocol: &str,
172+
) {
161173
let handle = tokio::runtime::Handle::current();
162174
let brokers = brokers.to_owned();
163175
let topic = topic.to_owned();
164176
let security_protocol = security_protocol.to_owned();
165177
// Spawn a separate thread to avoid calling block_on from within an async context.
166178
std::thread::spawn(move || {
167-
handle.block_on(setup_topic(&brokers, &topic, num_partitions, &security_protocol));
179+
handle.block_on(setup_topic(
180+
&brokers,
181+
&topic,
182+
num_partitions,
183+
&security_protocol,
184+
));
168185
})
169186
.join()
170187
.expect("Topic setup thread panicked");

0 commit comments

Comments
 (0)