2
2
mod results;
3
3
4
4
use crate :: agent:: api:: AgentApi ;
5
+ use crate :: agent:: results:: ResultsUploader ;
5
6
use crate :: config:: Config ;
6
7
use crate :: experiments:: Experiment ;
7
8
use crate :: prelude:: * ;
@@ -47,20 +48,16 @@ fn run_heartbeat(url: &str, token: &str) {
47
48
} ) ;
48
49
}
49
50
50
- fn try_with_report < T > ( api : & AgentApi , res : Fallible < T > ) -> Option < T > {
51
- match res {
52
- Err ( err) => {
53
- utils:: report_failure ( & err) ;
54
- if let Err ( e) = api
55
- . report_error ( format ! ( "{}" , err. find_root_cause( ) ) )
56
- . with_context ( |_| "error encountered" )
57
- {
58
- utils:: report_failure ( & e) ;
59
- }
60
- None
61
- }
62
- Ok ( res) => Some ( res) ,
63
- }
51
+ fn run_experiment (
52
+ agent : & Agent ,
53
+ db : & ResultsUploader ,
54
+ threads_count : usize ,
55
+ docker_env : & str ,
56
+ ) -> Fallible < ( ) > {
57
+ let ex = agent. experiment ( ) ?;
58
+ crate :: runner:: run_ex ( & ex, db, threads_count, & agent. config , docker_env) ?;
59
+ agent. api . complete_experiment ( ) ?;
60
+ Ok ( ( ) )
64
61
}
65
62
66
63
pub fn run ( url : & str , token : & str , threads_count : usize , docker_env : & str ) -> Fallible < ( ) > {
@@ -70,13 +67,15 @@ pub fn run(url: &str, token: &str, threads_count: usize, docker_env: &str) -> Fa
70
67
run_heartbeat ( url, token) ;
71
68
72
69
loop {
73
- try_with_report ( & agent. api , agent. experiment ( ) )
74
- . and_then ( |ex| {
75
- try_with_report (
76
- & agent. api ,
77
- crate :: runner:: run_ex ( & ex, & db, threads_count, & agent. config , docker_env) ,
78
- )
79
- } )
80
- . and_then ( |( ) | try_with_report ( & agent. api , agent. api . complete_experiment ( ) ) ) ;
70
+ if let Err ( err) = run_experiment ( & agent, & db, threads_count, docker_env) {
71
+ utils:: report_failure ( & err) ;
72
+ if let Err ( e) = agent
73
+ . api
74
+ . report_error ( format ! ( "{}" , err. find_root_cause( ) ) )
75
+ . with_context ( |_| "error encountered" )
76
+ {
77
+ utils:: report_failure ( & e) ;
78
+ }
79
+ }
81
80
}
82
81
}
0 commit comments