Skip to content

Commit 263bee0

Browse files
Make result a field rather than Vec
We only ever pass one element in this vec; this simplifies the API.
1 parent 01923db commit 263bee0

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

src/agent/api.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,12 @@ impl AgentApi {
182182
.build_request(Method::POST, "record-progress")
183183
.json(&json!({
184184
"experiment-name": ex.name,
185-
"results": [
186-
{
187-
"crate": krate,
188-
"toolchain": toolchain,
189-
"result": result,
190-
"log": base64::engine::general_purpose::STANDARD.encode(log),
191-
},
192-
],
185+
"result": {
186+
"crate": krate,
187+
"toolchain": toolchain,
188+
"result": result,
189+
"log": base64::engine::general_purpose::STANDARD.encode(log),
190+
},
193191
"version": version
194192
}))
195193
.send()?

src/results/db.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct TaskResult {
2020

2121
#[derive(Deserialize)]
2222
pub struct ProgressData {
23-
pub results: Vec<TaskResult>,
23+
pub result: TaskResult,
2424
pub version: Option<(Crate, Crate)>,
2525
}
2626

@@ -83,25 +83,23 @@ impl<'a> DatabaseDB<'a> {
8383
data: &ProgressData,
8484
encoding_type: EncodingType,
8585
) -> Fallible<()> {
86-
for result in &data.results {
87-
self.store_result(
88-
ex,
89-
&result.krate,
90-
&result.toolchain,
91-
&result.result,
92-
&base64::engine::general_purpose::STANDARD
93-
.decode(&result.log)
94-
.with_context(|_| "invalid base64 log provided")?,
95-
encoding_type,
96-
)?;
97-
98-
if let Some((old, new)) = &data.version {
99-
self.update_crate_version(ex, old, new)?;
100-
}
101-
102-
self.mark_crate_as_completed(ex, &result.krate)?;
86+
self.store_result(
87+
ex,
88+
&data.result.krate,
89+
&data.result.toolchain,
90+
&data.result.result,
91+
&base64::engine::general_purpose::STANDARD
92+
.decode(&data.result.log)
93+
.with_context(|_| "invalid base64 log provided")?,
94+
encoding_type,
95+
)?;
96+
97+
if let Some((old, new)) = &data.version {
98+
self.update_crate_version(ex, old, new)?;
10399
}
104100

101+
self.mark_crate_as_completed(ex, &data.result.krate)?;
102+
105103
Ok(())
106104
}
107105

@@ -465,12 +463,12 @@ mod tests {
465463
.store(
466464
&ex,
467465
&ProgressData {
468-
results: vec![TaskResult {
466+
result: TaskResult {
469467
krate: updated.clone(),
470468
toolchain: MAIN_TOOLCHAIN.clone(),
471469
result: TestResult::TestPass,
472470
log: base64::engine::general_purpose::STANDARD.encode("foo"),
473-
}],
471+
},
474472
version: Some((krate.clone(), updated.clone())),
475473
},
476474
EncodingType::Plain,

src/server/routes/agent.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ impl RecordProgressThread {
203203
crate::utils::report_failure(&e);
204204
}
205205

206-
metrics.record_completed_jobs(
207-
&ex.name,
208-
result.data.results.len() as u64,
209-
);
206+
metrics.record_completed_jobs(&ex.name, 1);
210207

211208
if let Err(e) = db.clear_stale_records() {
212209
// Not a hard failure. We can continue even if we failed
@@ -301,11 +298,7 @@ fn endpoint_record_progress(
301298
data: Arc<Data>,
302299
_auth: AuthDetails,
303300
) -> Fallible<Response<Body>> {
304-
match data
305-
.record_progress_worker
306-
.queue
307-
.try_send(result)
308-
{
301+
match data.record_progress_worker.queue.try_send(result) {
309302
Ok(()) => Ok(ApiResponse::Success { result: true }.into_response()?),
310303
Err(crossbeam_channel::TrySendError::Full(_)) => {
311304
data.metrics.crater_bounced_record_progress.inc_by(1);

0 commit comments

Comments
 (0)