Skip to content

Commit c34efe2

Browse files
committed
refactoring
1 parent 1931b11 commit c34efe2

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

atcoder-problems-backend/src/bin/crawl_for_virtual_contests.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ use std::{
1313

1414
const FIX_RANGE_SECOND: i64 = 10 * 60;
1515

16-
async fn crawl<R: Rng>(url: &str, rng: &mut R, client: AtCoderClient) -> Result<()> {
16+
async fn crawl<R: Rng>(url: &str, rng: &mut R, username: &str, password: &str) -> Result<()> {
1717
log::info!("Start crawling...");
1818
let pg_pool = initialize_pool(&url).await?;
19+
let client = AtCoderClient::new(username, password).await?;
1920
let mut crawler = VirtualContestCrawler::new(pg_pool.clone(), client.clone(), rng);
2021
crawler.crawl().await?;
2122
log::info!("Finished crawling");
2223

2324
log::info!("Starting fixing...");
2425
let cur = Utc::now().timestamp();
25-
let crawler = FixCrawler::new(pg_pool, client.clone(), cur - FIX_RANGE_SECOND);
26+
let crawler = FixCrawler::new(pg_pool, client, cur - FIX_RANGE_SECOND);
2627
crawler.crawl().await?;
2728
log::info!("Finished fixing");
2829

@@ -43,15 +44,8 @@ async fn main() {
4344
log::info!("Start new loop...");
4445
let now = Instant::now();
4546

46-
match AtCoderClient::new(&username, &password).await {
47-
Ok(client) => {
48-
if let Err(e) = crawl(&url, &mut rng, client).await {
49-
log::error!("{:?}", e);
50-
}
51-
}
52-
Err(e) => {
53-
log::error!("{:?}", e);
54-
}
47+
if let Err(e) = crawl(&url, &mut rng, &username, &password).await {
48+
log::error!("{:?}", e);
5549
}
5650

5751
let elapsed_secs = now.elapsed().as_secs();

0 commit comments

Comments
 (0)