aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTeddy Wing2021-06-12 16:09:52 +0200
committerTeddy Wing2021-06-12 16:09:52 +0200
commit90086d8bb49733c9599d1e07fd553653021e3299 (patch)
treeb93387c90c205de3329162ade0dd71c639b747ca /src
parent08c06d217cd2c63de4f032844d6d7856a0fb9657 (diff)
downloadreflectub-90086d8bb49733c9599d1e07fd553653021e3299.tar.bz2
main: Remove async database calls
Remove all the async database calls and Tokio spawning. Still haven't worked out the error code 21 database error from earlier, but this will hopefully allow us to use normal threads directly.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs59
1 files changed, 26 insertions, 33 deletions
diff --git a/src/main.rs b/src/main.rs
index 3e17c06..79ea0fa 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -34,7 +34,7 @@ use std::fs;
use std::io;
use std::path::{Path, PathBuf};
use std::process;
-use std::sync::Arc;
+use std::sync::{Arc, Mutex};
fn main() {
@@ -125,39 +125,32 @@ async fn run() -> anyhow::Result<()> {
let repos = github::fetch_repos(username).await?;
- let db = Arc::new(
- tokio::sync::Mutex::new(
- database::Db::connect(&database_file)?,
- )
- );
+ let mut db = database::Db::connect(&database_file)?;
- db.lock().await
- .create()?;
+ db.create()?;
// let mut joins = futures::stream::FuturesUnordered::new();
- let mut joins = Vec::with_capacity(repos.len());
+ // let mut joins = Vec::with_capacity(repos.len());
let mut i = 0;
for repo in repos {
- let db = db.clone();
+ // let db = db.clone();
let mirror_root = mirror_root.clone();
let base_cgitrc = base_cgitrc.clone();
// let join = tokio::runtime::Handle::current().spawn(async move {
- let join = tokio::task::spawn(async move {
- let mut db = db.lock().await;
- dbg!("processing on", std::thread::current().id());
+ // let mut db = db.lock()?;
- process_repo(
- &repo,
- &mut db,
- &mirror_root,
- base_cgitrc,
- max_repo_size_bytes,
- ).await
- });
+ process_repo(
+ &repo,
+ &mut db,
+ &mirror_root,
+ base_cgitrc,
+ max_repo_size_bytes,
+ );
+ // });
- joins.push(join);
+ // joins.push(join);
if i == 5 {
break;
@@ -166,29 +159,29 @@ async fn run() -> anyhow::Result<()> {
}
// executor::block_on(future::join_all(joins));
- let mut joins = tokio_stream::iter(&mut joins);
- let mut results = Vec::new();
-
- while let Some(task) = joins.next().await {
- let result = task.await;
- results.push(result);
- }
+ // let mut joins = tokio_stream::iter(&mut joins);
+ // let mut results = Vec::new();
+ //
+ // while let Some(task) = joins.next().await {
+ // let result = task.await;
+ // results.push(result);
+ // }
// for task in joins {
// // results.push(task.await);
// results.push(tokio::join!(task));
// }
- let errors = results.iter()
- .filter(|r| r.is_err());
+ // let errors = results.iter()
+ // .filter(|r| r.is_err());
- dbg!(&errors);
+ // dbg!(&errors);
Ok(())
}
/// Mirror or update `repo`.
-async fn process_repo(
+fn process_repo(
repo: &github::Repo,
db: &mut database::Db,
mirror_root: &str,