Skip to content

Commit 8581357

Browse files
refactor: remove the closure argument to poll in favor of polling options
1 parent bd0755a commit 8581357

5 files changed

Lines changed: 31 additions & 33 deletions

File tree

src/cli/exec/mod.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ use crate::instruments::Instruments;
77
use crate::prelude::*;
88
use crate::project_config::ProjectConfig;
99
use crate::project_config::merger::ConfigMerger;
10-
use crate::upload::UploadResult;
11-
use crate::upload::poll_results::{PollResultsOptions, poll_results};
10+
use crate::upload::poll_results::PollResultsOptions;
1211
use clap::Args;
1312
use std::path::Path;
1413
use url::Url;
@@ -89,6 +88,7 @@ fn build_orchestrator_config(
8988
skip_setup: args.shared.skip_setup,
9089
allow_empty: args.shared.allow_empty,
9190
go_runner_version: args.shared.go_runner_version,
91+
poll_results_options: PollResultsOptions::for_exec(),
9292
})
9393
}
9494

@@ -128,14 +128,7 @@ pub async fn execute_config(
128128

129129
debug!("config: {:#?}", orchestrator.config);
130130

131-
let poll_opts = PollResultsOptions::for_exec();
132-
let poll_results_fn = async |upload_result: &UploadResult| {
133-
poll_results(api_client, upload_result, &poll_opts).await
134-
};
135-
136-
orchestrator
137-
.execute(setup_cache_dir, poll_results_fn)
138-
.await?;
131+
orchestrator.execute(setup_cache_dir, api_client).await?;
139132

140133
Ok(())
141134
}

src/cli/run/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use crate::prelude::*;
88
use crate::project_config::ProjectConfig;
99
use crate::project_config::merger::ConfigMerger;
1010
use crate::run_environment::interfaces::RepositoryProvider;
11-
use crate::upload::UploadResult;
12-
use crate::upload::poll_results::{PollResultsOptions, poll_results};
11+
use crate::upload::poll_results::PollResultsOptions;
1312
use clap::{Args, ValueEnum};
1413
use std::path::Path;
1514
use url::Url;
@@ -96,6 +95,7 @@ impl RunArgs {
9695
fn build_orchestrator_config(
9796
args: RunArgs,
9897
targets: Vec<executor::BenchmarkTarget>,
98+
poll_results_options: PollResultsOptions,
9999
) -> Result<OrchestratorConfig> {
100100
let instruments = Instruments::try_from(&args)?;
101101
let modes = args.shared.resolve_modes()?;
@@ -127,6 +127,7 @@ fn build_orchestrator_config(
127127
skip_setup: args.shared.skip_setup,
128128
allow_empty: args.shared.allow_empty,
129129
go_runner_version: args.shared.go_runner_version,
130+
poll_results_options,
130131
})
131132
}
132133

@@ -185,6 +186,7 @@ pub async fn run(
185186
command,
186187
name: None,
187188
}],
189+
PollResultsOptions::for_run(output_json),
188190
)?;
189191
let orchestrator =
190192
executor::Orchestrator::new(config, codspeed_config, api_client).await?;
@@ -194,13 +196,7 @@ pub async fn run(
194196
}
195197
debug!("config: {:?}", orchestrator.config);
196198

197-
let poll_opts = PollResultsOptions::for_run(output_json);
198-
let poll_results_fn = async |upload_result: &UploadResult| {
199-
poll_results(api_client, upload_result, &poll_opts).await
200-
};
201-
orchestrator
202-
.execute(setup_cache_dir, poll_results_fn)
203-
.await?;
199+
orchestrator.execute(setup_cache_dir, api_client).await?;
204200
}
205201

206202
RunTarget::ConfigTargets {
@@ -210,7 +206,8 @@ pub async fn run(
210206
} => {
211207
let benchmark_targets =
212208
super::exec::multi_targets::build_benchmark_targets(targets, default_walltime)?;
213-
let config = build_orchestrator_config(args, benchmark_targets)?;
209+
let config =
210+
build_orchestrator_config(args, benchmark_targets, PollResultsOptions::for_exec())?;
214211
super::exec::execute_config(config, api_client, codspeed_config, setup_cache_dir)
215212
.await?;
216213
}

src/executor/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::instruments::Instruments;
33
use crate::prelude::*;
44
use crate::run_environment::RepositoryProvider;
55
use crate::runner_mode::RunnerMode;
6+
use crate::upload::poll_results::PollResultsOptions;
67
use clap::ValueEnum;
78
use semver::Version;
89
use std::path::PathBuf;
@@ -71,6 +72,8 @@ pub struct OrchestratorConfig {
7172
pub allow_empty: bool,
7273
/// The version of go-runner to install (if None, installs latest)
7374
pub go_runner_version: Option<Version>,
75+
/// Options controlling post-upload result polling and display
76+
pub poll_results_options: PollResultsOptions,
7477
}
7578

7679
/// Per-execution configuration passed to executors.
@@ -198,6 +201,7 @@ impl OrchestratorConfig {
198201
skip_setup: false,
199202
allow_empty: false,
200203
go_runner_version: None,
204+
poll_results_options: PollResultsOptions::for_exec(),
201205
}
202206
}
203207
}

src/executor/orchestrator.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::prelude::*;
1212
use crate::run_environment::{self, RunEnvironment, RunEnvironmentProvider};
1313
use crate::runner_mode::RunnerMode;
1414
use crate::system::{self, SystemInfo};
15+
use crate::upload::poll_results::poll_results;
1516
use crate::upload::{UploadResult, upload};
1617
use serde_json::Value;
1718
use std::collections::BTreeMap;
@@ -79,10 +80,11 @@ impl Orchestrator {
7980
/// Each `(command, mode)` pair gets its own profile folder. When the user
8081
/// specifies `--profile-folder` and there are multiple pairs, deterministic
8182
/// subdirectories (`<mode>-<index>`) are created under that folder.
82-
pub async fn execute<F>(&self, setup_cache_dir: Option<&Path>, poll_results: F) -> Result<()>
83-
where
84-
F: AsyncFn(&UploadResult) -> Result<()>,
85-
{
83+
pub async fn execute(
84+
&self,
85+
setup_cache_dir: Option<&Path>,
86+
api_client: &CodSpeedAPIClient,
87+
) -> Result<()> {
8688
// Build (command, label) pairs while we still know the target type
8789
let mut command_labels: Vec<(String, String)> = vec![];
8890

@@ -170,8 +172,7 @@ impl Orchestrator {
170172
end_group!();
171173
}
172174

173-
self.upload_and_poll(all_completed_runs, &poll_results)
174-
.await?;
175+
self.upload_and_poll(all_completed_runs, api_client).await?;
175176

176177
Ok(())
177178
}
@@ -204,14 +205,11 @@ impl Orchestrator {
204205
}
205206

206207
/// Upload completed runs and poll results.
207-
async fn upload_and_poll<F>(
208+
async fn upload_and_poll(
208209
&self,
209210
mut completed_runs: Vec<(ExecutionContext, ExecutorName)>,
210-
poll_results: F,
211-
) -> Result<()>
212-
where
213-
F: AsyncFn(&UploadResult) -> Result<()>,
214-
{
211+
api_client: &CodSpeedAPIClient,
212+
) -> Result<()> {
215213
let skip_upload = self.config.skip_upload;
216214

217215
if !skip_upload {
@@ -220,7 +218,12 @@ impl Orchestrator {
220218
end_group!();
221219

222220
if self.is_local() {
223-
poll_results(&last_upload_result).await?;
221+
poll_results(
222+
api_client,
223+
&last_upload_result,
224+
&self.config.poll_results_options,
225+
)
226+
.await?;
224227
}
225228
} else {
226229
debug!("Skipping upload of performance data");

src/upload/poll_results.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::prelude::*;
77
use super::{UploadResult, poll_run_report};
88

99
/// Options controlling poll_results display behavior.
10+
#[derive(Debug, Clone)]
1011
pub struct PollResultsOptions {
1112
/// If true, show impact percentage (used by `codspeed run`)
1213
pub show_impact: bool,

0 commit comments

Comments
 (0)