Commit
Author: Kevin Schoon [me@kevinschoon.com]
Hash: aa287ef3006960c2e77ed943102b1374664f5981
Timestamp: Mon, 27 May 2024 07:18:07 +0000 (11 months ago)

+18 -12 +/-5 browse
restore the depth flag on job commands
restore the depth flag on job commands

This adds the max_depth flag back to the Ayllu job CLI so that you can specify
--max-depth=90 for example to only process the most recent 90 commits rather
than traversing the entire git history of a project.
1diff --git a/ayllu/src/job_server/commands.rs b/ayllu/src/job_server/commands.rs
2index 2f7db87..b3b9e3f 100644
3--- a/ayllu/src/job_server/commands.rs
4+++ b/ayllu/src/job_server/commands.rs
5 @@ -53,7 +53,7 @@ pub async fn run_one(
6 config: Config,
7 repo_path: Option<PathBuf>,
8 kind: Option<&str>,
9- _max_depth: Option<usize>,
10+ max_depth: Option<i64>,
11 ) -> Result<()> {
12 let kinds: Vec<Kind> = kind.map_or(vec![Kind::Cloc, Kind::Contributors], |kind| {
13 vec![kind.to_string().into()]
14 @@ -66,7 +66,7 @@ pub async fn run_one(
15 .checked_add(StdDuration::from_secs(1200))
16 .unwrap();
17 client
18- .submit(ctx, kind, repo_path.display().to_string())
19+ .submit(ctx, kind, repo_path.display().to_string(), max_depth)
20 .await?;
21 }
22 Ok(())
23 diff --git a/ayllu/src/job_server/runner.rs b/ayllu/src/job_server/runner.rs
24index 3c3fd09..bdc60aa 100644
25--- a/ayllu/src/job_server/runner.rs
26+++ b/ayllu/src/job_server/runner.rs
27 @@ -18,9 +18,9 @@ pub struct Runner {
28 }
29
30 impl Runner {
31- pub fn new(job: Job, database: Arc<Database>) -> Self {
32+ pub fn new(job: Job, database: Arc<Database>, max_depth: Option<i64>) -> Self {
33 Runner {
34- max_depth: None,
35+ max_depth: max_depth.map(|depth| depth as usize),
36 database,
37 job,
38 }
39 diff --git a/ayllu/src/job_server/server.rs b/ayllu/src/job_server/server.rs
40index 3975b5c..66cf8c1 100644
41--- a/ayllu/src/job_server/server.rs
42+++ b/ayllu/src/job_server/server.rs
43 @@ -19,7 +19,13 @@ impl Server {
44
45 impl Api for Server {
46 #[doc = r" Submit a new job to be run in the background"]
47- async fn submit(self, _context: Context, kind: Kind, repo_path: String) {
48+ async fn submit(
49+ self,
50+ _context: Context,
51+ kind: Kind,
52+ repo_path: String,
53+ max_depth: Option<i64>,
54+ ) {
55 let db = self.db.clone();
56 let job = Job {
57 id: 0,
58 @@ -30,7 +36,7 @@ impl Api for Server {
59 success: false,
60 commits: 0,
61 };
62- Runner::new(job, db).run().await.expect("failed to run job");
63+ Runner::new(job, db, max_depth).run().await.expect("failed to run job");
64 }
65
66 #[doc = r" List submitted and complete jobs"]
67 diff --git a/ayllu/src/main.rs b/ayllu/src/main.rs
68index 2a7989d..008fdae 100644
69--- a/ayllu/src/main.rs
70+++ b/ayllu/src/main.rs
71 @@ -14,10 +14,10 @@ mod web2;
72
73 mod config;
74 mod database_ext;
75+ mod highlight;
76 mod languages;
77 mod license;
78 mod readme;
79- mod highlight;
80 mod time;
81
82 #[derive(Parser, Debug)]
83 @@ -35,8 +35,9 @@ struct Arguments {
84
85 #[derive(Args, Debug)]
86 struct JobArguments {
87- #[clap(short, long, default_value = "false")]
88- short: bool,
89+ #[clap(short, long)]
90+ /// Maximum amount of commits to traverse
91+ depth: Option<i64>,
92 /// Path to a git repository
93 path: Option<PathBuf>,
94 /// Job kind specifier.
95 @@ -190,9 +191,8 @@ fn main() -> Result<(), Box<dyn Error>> {
96 }
97 JobsCommand::Run {
98 all: _,
99- rest: JobArguments { path, short, kind },
100+ rest: JobArguments { path, depth, kind },
101 } => {
102- let depth = if short { Some(1) } else { None };
103 runtime.block_on(async {
104 tokio::task::LocalSet::new()
105 .run_until(job_server::run_one(cfg, path, kind.as_deref(), depth))
106 diff --git a/crates/api/src/jobs.rs b/crates/api/src/jobs.rs
107index 00e07b9..cb9010a 100644
108--- a/crates/api/src/jobs.rs
109+++ b/crates/api/src/jobs.rs
110 @@ -45,7 +45,7 @@ pub struct Job {
111 #[service]
112 pub trait Server {
113 /// Submit a new job to be run in the background
114- async fn submit(kind: Kind, repo_path: String);
115+ async fn submit(kind: Kind, repo_path: String, max_depth: Option<i64>);
116 /// List submitted and complete jobs
117 async fn list(repo_path: Option<String>) -> Vec<Job>;
118 /// Purge all jobs associated with the given repository