Skip to content

Commit 7f8bdb1

Browse files
committed
check: format
1 parent b46ae62 commit 7f8bdb1

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

check/src/main.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ use rayhunter::{
1212
};
1313
use serde::Serialize;
1414
use serde_json::json;
15-
use std::{collections::HashMap, future, path::{Path, PathBuf}, pin::pin};
15+
use std::{
16+
collections::HashMap,
17+
future,
18+
path::{Path, PathBuf},
19+
pin::pin,
20+
};
1621
use tokio::fs::{File, OpenOptions};
1722
use tokio::io::{AsyncWriteExt, BufWriter};
1823
use walkdir::WalkDir;
@@ -85,11 +90,7 @@ impl LogReport {
8590
}
8691
}
8792

88-
fn on_row(
89-
&mut self,
90-
timestamp: DateTime<FixedOffset>,
91-
events: Vec<Event>,
92-
) {
93+
fn on_row(&mut self, timestamp: DateTime<FixedOffset>, events: Vec<Event>) {
9394
for event in events {
9495
match event.event_type {
9596
EventType::Informational => {
@@ -127,10 +128,7 @@ struct NdjsonReport {
127128
// The `njson` report has the same output format as the daemon analysis report.
128129
// See also: [Newline Delimited JSON](https://docs.mulesoft.com/dataweave/latest/dataweave-formats-ndjson)
129130
impl NdjsonReport {
130-
async fn new(
131-
file_path: &str,
132-
metadata: &ReportMetadata,
133-
) -> std::io::Result<Self> {
131+
async fn new(file_path: &str, metadata: &ReportMetadata) -> std::io::Result<Self> {
134132
let mut report_path = PathBuf::from(file_path);
135133
report_path.set_extension("ndjson");
136134
let writer = OpenOptions::new()
@@ -141,9 +139,7 @@ impl NdjsonReport {
141139
.await
142140
.map(BufWriter::new)?;
143141

144-
let mut r = NdjsonReport {
145-
writer,
146-
};
142+
let mut r = NdjsonReport { writer };
147143

148144
// The first wrote of the ndjson report is the analysis metadata
149145
r.write(metadata).await?;
@@ -157,22 +153,23 @@ impl NdjsonReport {
157153
self.writer.write_all(value_str.as_bytes()).await
158154
}
159155

160-
async fn on_row(
161-
&mut self,
162-
timestamp: DateTime<FixedOffset>,
163-
events: Vec<Event>,
164-
) {
156+
async fn on_row(&mut self, timestamp: DateTime<FixedOffset>, events: Vec<Event>) {
165157
let value = json!({
166158
"packet_timestamp": timestamp.to_rfc3339(),
167159
"events": events,
168160
"skipped_message_reason": "TODO",
169161
});
170162

171-
self.write(&value).await.expect("failed to write ndjson row");
163+
self.write(&value)
164+
.await
165+
.expect("failed to write ndjson row");
172166
}
173167

174168
async fn on_finish(&mut self, _summary: &Summary) {
175-
self.writer.flush().await.expect("failed to flush ndjson report");
169+
self.writer
170+
.flush()
171+
.await
172+
.expect("failed to flush ndjson report");
176173
}
177174
}
178175

@@ -211,11 +208,11 @@ impl Report {
211208
return;
212209
}
213210

214-
let events = row
215-
.events
216-
.into_iter()
217-
.flatten()
218-
.collect::<Vec<Event>>();
211+
let events = row.events.into_iter().flatten().collect::<Vec<Event>>();
212+
213+
if events.is_empty() {
214+
return;
215+
}
219216

220217
match &mut self.dest {
221218
ReportDest::Log(r) => r.on_row(row.packet_timestamp.unwrap(), events),

0 commit comments

Comments
 (0)