22mod results;
33
44use crate :: agent:: api:: AgentApi ;
5+ use crate :: agent:: results:: ResultsUploader ;
56use crate :: config:: Config ;
67use crate :: experiments:: Experiment ;
78use crate :: prelude:: * ;
@@ -47,20 +48,16 @@ fn run_heartbeat(url: &str, token: &str) {
4748 } ) ;
4849}
4950
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 ( ( ) )
6461}
6562
6663pub 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
7067 run_heartbeat ( url, token) ;
7168
7269 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+ }
8180 }
8281}
0 commit comments