Skip to content

Commit 2fce63a

Browse files
committed
report errors from agent loop
1 parent 2803f91 commit 2fce63a

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/agent/api.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,15 @@ impl AgentApi {
190190
Ok(())
191191
})
192192
}
193+
194+
pub fn report_error(&self, error: String) -> Fallible<()> {
195+
self.retry(|this| {
196+
let _: bool = this
197+
.build_request(Method::POST, "error")
198+
.json(&json!({ "error": error }))
199+
.send()?
200+
.to_api_response()?;
201+
Ok(())
202+
})
203+
}
193204
}

src/agent/mod.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,36 @@ fn run_heartbeat(url: &str, token: &str) {
4747
});
4848
}
4949

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+
}
64+
}
65+
5066
pub fn run(url: &str, token: &str, threads_count: usize, docker_env: &str) -> Fallible<()> {
5167
let agent = Agent::new(url, token)?;
5268
let db = results::ResultsUploader::new(&agent.api);
5369

5470
run_heartbeat(url, token);
5571

5672
loop {
57-
let ex = agent.experiment()?;
58-
crate::runner::run_ex(&ex, &db, threads_count, &agent.config, docker_env)?;
59-
agent.api.complete_experiment()?;
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()));
6081
}
6182
}

0 commit comments

Comments
 (0)