Skip to content

Commit b3c635c

Browse files
Merge pull request #29 from reddevilmidzy/refactor
코드 재구성
2 parents d44fc5f + 589ebc3 commit b3c635c

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ regex = "1"
1414
reqwest = { version = "0.12", features = ["json"] }
1515
tokio = { version = "1", features = ["full"] }
1616
git2 = "0.20"
17+
serde = { version = "1.0", features = ["derive"] }
18+
serde_json = "1.0"

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub mod git;
2+
pub mod link;
3+
pub mod schedule;
4+
5+
pub use git::*;
6+
pub use link::*;
7+
pub use schedule::*;

src/main.rs

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,48 @@
1-
mod git;
2-
mod link;
3-
mod schedule;
1+
use queensac::check_repository_links;
42

5-
use crate::schedule::check_repository_links;
6-
use axum::{Router, routing::get};
3+
use axum::{
4+
Json, Router,
5+
routing::{get, post},
6+
serve,
7+
};
8+
use serde::Deserialize;
79
use std::time::Duration;
10+
use tokio::net::TcpListener;
11+
12+
async fn spawn_repository_checker(repo_url: &str, interval: Duration) {
13+
let repo_url = repo_url.to_string();
14+
tokio::spawn(async move {
15+
check_repository_links(&repo_url, interval).await;
16+
});
17+
}
818

919
async fn health_check() -> &'static str {
1020
"OK"
1121
}
1222

23+
#[derive(Deserialize)]
24+
struct CheckRequest {
25+
repo_url: String,
26+
interval_secs: u64,
27+
}
28+
29+
async fn check_handler(Json(payload): Json<CheckRequest>) -> &'static str {
30+
let interval = Duration::from_secs(payload.interval_secs);
31+
spawn_repository_checker(&payload.repo_url, interval).await;
32+
"Repository checker started"
33+
}
34+
1335
#[tokio::main]
1436
async fn main() {
15-
let app = Router::new().route("/check", get(health_check));
37+
let app = app();
38+
let listener = TcpListener::bind("localhost:3000").await.unwrap();
1639

17-
let listener = tokio::net::TcpListener::bind("localhost:3000")
18-
.await
19-
.unwrap();
20-
21-
let repo_url = "https://github.com/reddevilmidzy/redddy-action";
22-
let interval_duration = Duration::from_secs(60);
23-
let _repo_check = check_repository_links(repo_url, interval_duration);
40+
serve(listener, app).await.unwrap();
41+
}
2442

25-
axum::serve(listener, app).await.unwrap();
43+
fn app() -> Router {
44+
Router::new()
45+
.route("/", get(|| async { "Sacrifice the Queen!!" }))
46+
.route("/health", get(health_check))
47+
.route("/check", post(check_handler))
2648
}

src/schedule/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// TODO: Review the usage of the 'link' and 'git' modules in this file.
2+
// Verify if their usage aligns with the intended design and functionality.
3+
// If necessary, refer to issue #123 for further context and discussion.
14
use crate::git;
25
use crate::link::{LinkCheckResult, check_link};
36
use chrono::Local;

0 commit comments

Comments
 (0)