1
1
use super :: db;
2
- use crate :: corpus:: Engine ;
2
+ use crate :: corpus:: { Engine , Task } ;
3
3
use crate :: organize:: find_git_repository_workdirs;
4
- use anyhow:: Context ;
4
+ use anyhow:: { bail , Context } ;
5
5
use bytesize:: ByteSize ;
6
+ use gix:: Progress ;
6
7
use rusqlite:: params;
7
8
use std:: path:: { Path , PathBuf } ;
8
9
use std:: time:: Instant ;
9
10
10
- pub ( crate ) type Id = u32 ;
11
-
12
11
impl < P > Engine < P >
13
12
where
14
13
P : gix:: Progress ,
29
28
let gitoxide_id = self . gitoxide_version_id_or_insert ( ) ?;
30
29
let runner_id = self . runner_id_or_insert ( ) ?;
31
30
let repos = self . find_repos_or_insert ( & corpus_path, corpus_id) ?;
32
- self . perform_run ( gitoxide_id, runner_id, repos)
31
+ let tasks = self . tasks_or_insert ( ) ?;
32
+ self . perform_run ( gitoxide_id, runner_id, & tasks, & repos)
33
33
}
34
34
35
35
pub fn refresh ( & mut self , corpus_path : PathBuf ) -> anyhow:: Result < ( ) > {
@@ -48,17 +48,51 @@ impl<P> Engine<P>
48
48
where
49
49
P : gix:: Progress ,
50
50
{
51
- fn perform_run ( & self , _gitoxide_id : Id , _runner_id : Id , _repos : Vec < db:: Repo > ) -> anyhow:: Result < ( ) > {
52
- todo ! ( )
51
+ fn perform_run (
52
+ & mut self ,
53
+ gitoxide_id : db:: Id ,
54
+ runner_id : db:: Id ,
55
+ tasks : & [ ( db:: Id , & ' static Task ) ] ,
56
+ repos : & [ db:: Repo ] ,
57
+ ) -> anyhow:: Result < ( ) > {
58
+ let start = Instant :: now ( ) ;
59
+ let task_progress = & mut self . progress ;
60
+ task_progress. set_name ( "run" ) ;
61
+ task_progress. init ( Some ( tasks. len ( ) ) , gix:: progress:: count ( "tasks" ) ) ;
62
+ for ( task_id, task) in tasks {
63
+ let task_start = Instant :: now ( ) ;
64
+ let mut run_progress = task_progress. add_child ( format ! ( "run '{}'" , task. name) ) ;
65
+ run_progress. init ( Some ( repos. len ( ) ) , gix:: progress:: count ( "repos" ) ) ;
66
+
67
+ if task. execute_exclusive {
68
+ for repo in repos {
69
+ if gix:: interrupt:: is_triggered ( ) {
70
+ bail ! ( "interrupted by user" ) ;
71
+ }
72
+ let mut run = Self :: insert_run ( & self . con , gitoxide_id, runner_id, * task_id, repo. id ) ?;
73
+ task. perform ( & mut run, & repo. path ) ;
74
+ Self :: update_run ( & self . con , run) ?;
75
+ run_progress. inc ( ) ;
76
+ }
77
+ } else {
78
+ // gix::parallel::in_parallel_with_slice()
79
+ todo ! ( "shared" )
80
+ }
81
+
82
+ run_progress. show_throughput ( task_start) ;
83
+ task_progress. inc ( ) ;
84
+ }
85
+ task_progress. show_throughput ( start) ;
86
+ Ok ( ( ) )
53
87
}
54
88
55
- fn prepare_corpus_path ( & self , corpus_path : PathBuf ) -> anyhow:: Result < ( PathBuf , Id ) > {
89
+ fn prepare_corpus_path ( & self , corpus_path : PathBuf ) -> anyhow:: Result < ( PathBuf , db :: Id ) > {
56
90
let corpus_path = gix:: path:: realpath ( corpus_path) ?;
57
91
let corpus_id = self . corpus_id_or_insert ( & corpus_path) ?;
58
92
Ok ( ( corpus_path, corpus_id) )
59
93
}
60
94
61
- fn find_repos ( & mut self , corpus_id : Id ) -> anyhow:: Result < Vec < db:: Repo > > {
95
+ fn find_repos ( & mut self , corpus_path : & Path , corpus_id : db :: Id ) -> anyhow:: Result < Vec < db:: Repo > > {
62
96
self . progress . set_name ( "query db-repos" ) ;
63
97
self . progress . init ( None , gix:: progress:: count ( "repos" ) ) ;
64
98
68
102
. query_map ( [ corpus_id] , |r| {
69
103
Ok ( db:: Repo {
70
104
id : r. get ( 0 ) ?,
71
- path : r. get :: < _ , String > ( 1 ) ?. into ( ) ,
105
+ path : corpus_path . join ( r. get :: < _ , String > ( 1 ) ?) ,
72
106
odb_size : ByteSize ( r. get ( 2 ) ?) ,
73
107
num_objects : r. get ( 3 ) ?,
74
108
num_references : r. get ( 4 ) ?,
78
112
. collect :: < Result < _ , _ > > ( ) ?)
79
113
}
80
114
81
- fn refresh_repos ( & mut self , corpus_path : & Path , corpus_id : Id ) -> anyhow:: Result < Vec < db:: Repo > > {
115
+ fn refresh_repos ( & mut self , corpus_path : & Path , corpus_id : db :: Id ) -> anyhow:: Result < Vec < db:: Repo > > {
82
116
let start = Instant :: now ( ) ;
83
117
self . progress . set_name ( "refresh" ) ;
84
118
self . progress . init ( None , gix:: progress:: count ( "repos" ) ) ;
@@ -117,7 +151,6 @@ where
117
151
let write_db = scope. spawn ( move || -> anyhow:: Result < Vec < db:: Repo > > {
118
152
progress. set_name ( "write to DB" ) ;
119
153
progress. init ( None , gix:: progress:: count ( "repos" ) ) ;
120
- let start = Instant :: now ( ) ;
121
154
122
155
let mut out = Vec :: new ( ) ;
123
156
let transaction = con. transaction ( ) ?;
@@ -154,13 +187,12 @@ where
154
187
}
155
188
} ) ?;
156
189
157
- self . progress . show_throughput ( start) ;
158
190
Ok ( repos)
159
191
}
160
192
161
- fn find_repos_or_insert ( & mut self , corpus_path : & Path , corpus_id : Id ) -> anyhow:: Result < Vec < db:: Repo > > {
193
+ fn find_repos_or_insert ( & mut self , corpus_path : & Path , corpus_id : db :: Id ) -> anyhow:: Result < Vec < db:: Repo > > {
162
194
let start = Instant :: now ( ) ;
163
- let repos = self . find_repos ( corpus_id) ?;
195
+ let repos = self . find_repos ( corpus_path , corpus_id) ?;
164
196
if repos. is_empty ( ) {
165
197
self . refresh_repos ( corpus_path, corpus_id)
166
198
} else {
0 commit comments