diff --git a/Cargo.toml b/Cargo.toml
index 4314e4b..e90f266 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -33,7 +33,7 @@ mime = "0.3.16"
mime_guess = "2.0.3"
rand = "0.8.5"
tera = "1.15"
-tokio = { version = "1.17", features = ["fs", "time"] }
+tokio = { version = "1.17", features = ["fs", "time", "sync"] }
url = { version = "2.2.2", features = ["serde"] }
validator = { version = "0.15", features = ["derive"]}
derive_more = "0.99.17"
diff --git a/src/main.rs b/src/main.rs
index 51894ac..d0b52fe 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -20,6 +20,7 @@ use std::sync::Arc;
use actix_files::Files;
use actix_web::{middleware, web::Data, App, HttpServer};
use lazy_static::lazy_static;
+use tokio::sync::oneshot;
pub mod ctx;
pub mod db;
@@ -66,10 +67,20 @@ async fn main() {
pretty_env_logger::init();
lazy_static::initialize(&pages::TEMPLATES);
- let ctx = WebCtx::new(Ctx::new(settings.clone()).await);
+ let ctx = Ctx::new(settings.clone()).await;
let db = WebDB::new(sqlite::get_data(Some(settings.clone())).await);
let federate = WebFederate::new(get_federate(Some(settings.clone())).await);
+ let (kill_crawler, rx) = oneshot::channel();
+ let crawler = spider::Crawler::new(
+ rx,
+ ctx.clone(),
+ db.as_ref().clone(),
+ federate.as_ref().clone(),
+ );
+
+ let crawler_fut = tokio::spawn(spider::Crawler::start(crawler.clone()));
+ let ctx = WebCtx::new(ctx);
let socket_addr = settings.server.get_ip();
HttpServer::new(move || {
@@ -90,4 +101,7 @@ async fn main() {
.run()
.await
.unwrap();
+
+ kill_crawler.send(true).unwrap();
+ crawler_fut.await.unwrap().await;
}
diff --git a/src/spider.rs b/src/spider.rs
index e75b104..05ac171 100644
--- a/src/spider.rs
+++ b/src/spider.rs
@@ -16,6 +16,8 @@
* along with this program. If not, see .
*/
use std::future::Future;
+use std::sync::Arc;
+use std::sync::RwLock;
use log::info;
use tokio::sync::oneshot::{error::TryRecvError, Receiver};
@@ -119,6 +121,105 @@ impl Ctx {
}
}
+pub struct Crawler {
+ rx: RwLock