Commit
+33 -2 +/-2 browse
1 | diff --git a/ayllu-jobs/src/main.rs b/ayllu-jobs/src/main.rs |
2 | index 7f88d94..a246a5b 100644 |
3 | --- a/ayllu-jobs/src/main.rs |
4 | +++ b/ayllu-jobs/src/main.rs |
5 | @@ -45,6 +45,8 @@ enum JobsCommand { |
6 | Run(JobArguments), |
7 | /// Purge data from the database. |
8 | Purge(JobArguments), |
9 | + /// Run all jobs against all repositories in all collections |
10 | + RunAll, |
11 | } |
12 | |
13 | fn init_logger(level: Level) { |
14 | @@ -88,12 +90,15 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { |
15 | HashSet::from_iter(vec![Kind::Contributors, Kind::Cloc]) |
16 | }; |
17 | runner.run_one(job_arguments.path.as_path(), kinds).await?; |
18 | - // runner.run_one() |
19 | } |
20 | JobsCommand::Purge(job_arguments) => { |
21 | let runner = Runner::new(&cfg).await?; |
22 | runner.purge(job_arguments.path.as_path()).await?; |
23 | } |
24 | + JobsCommand::RunAll => { |
25 | + let runner = Runner::new(&cfg).await?; |
26 | + runner.run_all().await?; |
27 | + } |
28 | } |
29 | Ok(()) |
30 | } |
31 | diff --git a/ayllu-jobs/src/runner.rs b/ayllu-jobs/src/runner.rs |
32 | index 62878cd..259b04f 100644 |
33 | --- a/ayllu-jobs/src/runner.rs |
34 | +++ b/ayllu-jobs/src/runner.rs |
35 | @@ -8,7 +8,7 @@ use ayllu_database::{ |
36 | contributors::ContributorsExt, jobs::JobsExt, languages::LanguagesExt, Builder, |
37 | Wrapper as Database, |
38 | }; |
39 | - use ayllu_git::Wrapper as Repository; |
40 | + use ayllu_git::{Scanner, Wrapper as Repository}; |
41 | use tabwriter::TabWriter; |
42 | use time::{Duration, OffsetDateTime}; |
43 | |
44 | @@ -74,9 +74,35 @@ impl Runner<'_> { |
45 | } |
46 | } |
47 | |
48 | + pub async fn run_all(&self) -> Result<(), Error> { |
49 | + let paths: Vec<PathBuf> = |
50 | + self.cfg |
51 | + .collections |
52 | + .iter() |
53 | + .try_fold(Vec::new(), |mut accm, collection| { |
54 | + Scanner::from_path(&collection.path)? |
55 | + .fold(Vec::new(), |mut accm, path| { |
56 | + accm.push(path.clone()); |
57 | + accm |
58 | + }) |
59 | + .iter() |
60 | + .for_each(|path| accm.push(path.clone())); |
61 | + Ok::<Vec<PathBuf>, std::io::Error>(accm) |
62 | + })?; |
63 | + for path in paths { |
64 | + self.run_one( |
65 | + path.as_path(), |
66 | + HashSet::from_iter(vec![Kind::Cloc, Kind::Contributors]), |
67 | + ) |
68 | + .await?; |
69 | + } |
70 | + Ok(()) |
71 | + } |
72 | + |
73 | pub async fn run_one(&self, path: &Path, kinds: HashSet<Kind>) -> Result<(), Error> { |
74 | let path = self.resolve_path(path)?; |
75 | let repo_path_str = path.to_str().unwrap(); |
76 | + tracing::info!("Processing repository: {}", repo_path_str); |
77 | // FIXME Latest commit per kind |
78 | let latest_commit = self.db.latest_commit(path.to_str().unwrap()).await?; |
79 | let repository = Repository::new(path.as_path())?; |