Skip to content

Commit

Permalink
Make result a field rather than Vec
Browse files Browse the repository at this point in the history
We only ever pass one element in this vec; this simplifies the API.
  • Loading branch information
Mark-Simulacrum committed Oct 29, 2023
1 parent 173ea8e commit 0228d4e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
14 changes: 6 additions & 8 deletions src/agent/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,12 @@ impl AgentApi {
.build_request(Method::POST, "record-progress")
.json(&json!({
"experiment-name": ex.name,
"results": [
{
"crate": krate,
"toolchain": toolchain,
"result": result,
"log": base64::engine::general_purpose::STANDARD.encode(log),
},
],
"result": {
"crate": krate,
"toolchain": toolchain,
"result": result,
"log": base64::engine::general_purpose::STANDARD.encode(log),
},
"version": version
}))
.send()?
Expand Down
38 changes: 18 additions & 20 deletions src/results/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct TaskResult {

#[derive(Deserialize)]
pub struct ProgressData {
pub results: Vec<TaskResult>,
pub result: TaskResult,
pub version: Option<(Crate, Crate)>,
}

Expand Down Expand Up @@ -83,25 +83,23 @@ impl<'a> DatabaseDB<'a> {
data: &ProgressData,
encoding_type: EncodingType,
) -> Fallible<()> {
for result in &data.results {
self.store_result(
ex,
&result.krate,
&result.toolchain,
&result.result,
&base64::engine::general_purpose::STANDARD
.decode(&result.log)
.with_context(|_| "invalid base64 log provided")?,
encoding_type,
)?;

if let Some((old, new)) = &data.version {
self.update_crate_version(ex, old, new)?;
}

self.mark_crate_as_completed(ex, &result.krate)?;
self.store_result(
ex,
&data.result.krate,
&data.result.toolchain,
&data.result.result,
&base64::engine::general_purpose::STANDARD
.decode(&data.result.log)
.with_context(|_| "invalid base64 log provided")?,
encoding_type,
)?;

if let Some((old, new)) = &data.version {
self.update_crate_version(ex, old, new)?;
}

self.mark_crate_as_completed(ex, &data.result.krate)?;

Ok(())
}

Expand Down Expand Up @@ -465,12 +463,12 @@ mod tests {
.store(
&ex,
&ProgressData {
results: vec![TaskResult {
result: TaskResult {
krate: updated.clone(),
toolchain: MAIN_TOOLCHAIN.clone(),
result: TestResult::TestPass,
log: base64::engine::general_purpose::STANDARD.encode("foo"),
}],
},
version: Some((krate.clone(), updated.clone())),
},
EncodingType::Plain,
Expand Down
11 changes: 2 additions & 9 deletions src/server/routes/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ impl RecordProgressThread {
crate::utils::report_failure(&e);
}

metrics.record_completed_jobs(
&ex.name,
result.data.results.len() as u64,
);
metrics.record_completed_jobs(&ex.name, 1);

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

0 comments on commit 0228d4e

Please sign in to comment.