Skip to content

Commit f4f89e4

Browse files
committed
feat: async file
1 parent 627f5d8 commit f4f89e4

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/channel.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use octocrab::models::events::payload::EventPayload::{
1010
use rust_decimal::Decimal;
1111
use rust_decimal::prelude::*;
1212
use std::env;
13-
use std::fs::File;
1413
use std::io::{BufRead, BufReader};
1514
use std::path::PathBuf;
16-
use std::sync::Arc;
1715
use tokio::fs;
16+
use tokio::fs::File;
1817
use tokio::process::Command;
1918
use tokio::task::JoinSet;
2019

@@ -38,8 +37,6 @@ pub async fn start_channel() -> Result<()> {
3837

3938
init_pg().await?;
4039

41-
let rx = Arc::new(rx);
42-
4340
let mut consumers = JoinSet::new();
4441

4542
for _ in 0..max_concurrent {
@@ -151,7 +148,7 @@ async fn try_open_file(file_path: &PathBuf) -> Option<File> {
151148
.unwrap_or(3);
152149

153150
for i in 0..max_retries {
154-
if let Ok(file) = File::open(file_path) {
151+
if let Ok(file) = File::open(file_path).await {
155152
return Some(file);
156153
}
157154

@@ -177,7 +174,7 @@ async fn try_open_file(file_path: &PathBuf) -> Option<File> {
177174
#[tracing::instrument]
178175
async fn load_gh_event(file_path: PathBuf) -> Vec<EventTableStruct> {
179176
let file = match try_open_file(&file_path).await {
180-
Some(file) => file,
177+
Some(file) => file.into_std().await,
181178
None => return vec![],
182179
};
183180
let decoder = GzDecoder::new(file);

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod channel;
22
mod db;
33

4+
use crate::channel::start_channel;
45
use anyhow::Result;
56
use dotenvy::dotenv;
67
use std::time::Instant;
@@ -11,7 +12,6 @@ use tracing_subscriber::{
1112
layer::SubscriberExt,
1213
util::SubscriberInitExt,
1314
};
14-
use crate::channel::start_channel;
1515

1616
#[tokio::main]
1717
async fn main() -> Result<()> {

0 commit comments

Comments
 (0)