Skip to content

Commit bbe2df7

Browse files
refactor: remove logic from the run module
1 parent f911858 commit bbe2df7

32 files changed

Lines changed: 174 additions & 189 deletions

src/cli/exec/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::api_client::CodSpeedAPIClient;
22
use crate::binary_installer::ensure_binary_installed;
33
use crate::cli::run::show_banner;
4-
use crate::cli::run::uploader::UploadResult;
54
use crate::config::CodSpeedConfig;
65
use crate::executor;
76
use crate::prelude::*;
87
use crate::project_config::ProjectConfig;
98
use crate::project_config::merger::ConfigMerger;
9+
use crate::upload::UploadResult;
1010
use clap::Args;
1111
use std::path::Path;
1212

src/cli/exec/poll_results.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,16 @@
11
use console::style;
2-
use tokio::time::{Instant, sleep};
32

4-
use crate::api_client::{
5-
CodSpeedAPIClient, FetchLocalRunReportResponse, FetchLocalRunReportVars, RunStatus,
6-
};
7-
use crate::cli::run::helpers::benchmark_display::{
8-
POLLING_INTERVAL, RUN_PROCESSING_MAX_DURATION, build_benchmark_table, build_detailed_summary,
9-
};
10-
use crate::cli::run::uploader::UploadResult;
3+
use crate::api_client::CodSpeedAPIClient;
4+
use crate::cli::run::helpers::benchmark_display::{build_benchmark_table, build_detailed_summary};
115
use crate::prelude::*;
6+
use crate::upload::{UploadResult, poll_run_report};
127

138
#[allow(clippy::borrowed_box)]
149
pub async fn poll_results(
1510
api_client: &CodSpeedAPIClient,
1611
upload_result: &UploadResult,
1712
) -> Result<()> {
18-
let start = Instant::now();
19-
let fetch_local_run_report_vars = FetchLocalRunReportVars {
20-
owner: upload_result.owner.clone(),
21-
name: upload_result.repository.clone(),
22-
run_id: upload_result.run_id.clone(),
23-
};
24-
25-
let response;
26-
loop {
27-
if start.elapsed() > RUN_PROCESSING_MAX_DURATION {
28-
bail!("Polling results timed out");
29-
}
30-
31-
let fetch_result = api_client
32-
.fetch_local_run_report(fetch_local_run_report_vars.clone())
33-
.await?;
34-
35-
match fetch_result {
36-
FetchLocalRunReportResponse { run, .. }
37-
if run.status == RunStatus::Pending || run.status == RunStatus::Processing =>
38-
{
39-
sleep(POLLING_INTERVAL).await;
40-
}
41-
response_from_api => {
42-
response = response_from_api;
43-
break;
44-
}
45-
}
46-
}
47-
48-
if response.run.status == RunStatus::Failure {
49-
bail!("Run failed to be processed, try again in a few minutes");
50-
}
13+
let response = poll_run_report(api_client, upload_result).await?;
5114

5215
if !response.run.results.is_empty() {
5316
end_group!();

src/cli/run/helpers/benchmark_display.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ use crate::api_client::FetchLocalRunBenchmarkResult;
22
use crate::cli::run::helpers;
33
use crate::executor::ExecutorName;
44
use std::collections::HashMap;
5-
use std::time::Duration;
65
use tabled::settings::object::{Columns, Rows};
76
use tabled::settings::panel::Panel;
87
use tabled::settings::style::HorizontalLine;
98
use tabled::settings::{Alignment, Color, Modify, Style};
109
use tabled::{Table, Tabled};
1110

12-
pub const RUN_PROCESSING_MAX_DURATION: Duration = Duration::from_secs(60 * 5); // 5 minutes
13-
pub const POLLING_INTERVAL: Duration = Duration::from_secs(1);
14-
1511
fn format_with_thousands_sep(n: u64) -> String {
1612
let s = n.to_string();
1713
let mut result = String::new();

src/cli/run/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,14 @@ use crate::project_config::ProjectConfig;
88
use crate::project_config::merger::ConfigMerger;
99
use crate::run_environment::interfaces::RepositoryProvider;
1010
use crate::runner_mode::RunnerMode;
11+
use crate::upload::UploadResult;
1112
use clap::{Args, ValueEnum};
1213
use std::path::Path;
1314
use std::path::PathBuf;
14-
use uploader::UploadResult;
1515

16-
pub mod check_system;
1716
pub mod helpers;
18-
pub(crate) mod poll_results;
19-
pub mod run_index_state;
20-
pub(crate) mod uploader;
21-
2217
pub mod logger;
18+
mod poll_results;
2319

2420
pub(crate) fn show_banner() {
2521
let banner = format!(

src/cli/run/poll_results.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,17 @@
11
use console::style;
2-
use tokio::time::{Instant, sleep};
32

4-
use crate::api_client::{
5-
CodSpeedAPIClient, FetchLocalRunReportResponse, FetchLocalRunReportVars, RunStatus,
6-
};
7-
use crate::cli::run::helpers::benchmark_display::{
8-
POLLING_INTERVAL, RUN_PROCESSING_MAX_DURATION, build_benchmark_table,
9-
};
10-
use crate::cli::run::uploader::UploadResult;
3+
use crate::api_client::CodSpeedAPIClient;
4+
use crate::cli::run::helpers::benchmark_display::build_benchmark_table;
115
use crate::prelude::*;
6+
use crate::upload::{UploadResult, poll_run_report};
127

138
#[allow(clippy::borrowed_box)]
149
pub async fn poll_results(
1510
api_client: &CodSpeedAPIClient,
1611
upload_result: &UploadResult,
1712
output_json: bool,
1813
) -> Result<()> {
19-
let start = Instant::now();
20-
let fetch_local_run_report_vars = FetchLocalRunReportVars {
21-
owner: upload_result.owner.clone(),
22-
name: upload_result.repository.clone(),
23-
run_id: upload_result.run_id.clone(),
24-
};
25-
26-
let response;
27-
loop {
28-
if start.elapsed() > RUN_PROCESSING_MAX_DURATION {
29-
bail!("Polling results timed out");
30-
}
31-
32-
let fetch_result = api_client
33-
.fetch_local_run_report(fetch_local_run_report_vars.clone())
34-
.await?;
35-
36-
match fetch_result {
37-
FetchLocalRunReportResponse { run, .. }
38-
if run.status == RunStatus::Pending || run.status == RunStatus::Processing =>
39-
{
40-
sleep(POLLING_INTERVAL).await;
41-
}
42-
response_from_api => {
43-
response = response_from_api;
44-
break;
45-
}
46-
}
47-
}
48-
49-
if response.run.status == RunStatus::Failure {
50-
bail!("Run failed to be processed, try again in a few minutes");
51-
}
14+
let response = poll_run_report(api_client, upload_result).await?;
5215

5316
let report = response
5417
.run

src/cli/run/uploader/mod.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/cli/run/uploader/snapshots/codspeed_runner__cli__run__uploader__upload_metadata__tests__get_metadata_hash-2.snap

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/cli/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::cli::run::check_system::SystemInfo;
21
use crate::executor::get_all_executors;
32
use crate::prelude::*;
3+
use crate::system::SystemInfo;
44
use std::path::Path;
55

66
pub async fn setup(setup_cache_dir: Option<&Path>) -> Result<()> {

src/executor/execution_context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::Config;
2-
use crate::cli::run::check_system::{self, SystemInfo};
32
use crate::cli::run::logger::Logger;
43
use crate::config::CodSpeedConfig;
54
use crate::prelude::*;
65
use crate::run_environment::{self, RunEnvironment};
76
use crate::runner_mode::RunnerMode;
7+
use crate::system::{self, SystemInfo};
88
use std::path::PathBuf;
99

1010
use super::create_profile_folder;
@@ -39,7 +39,7 @@ impl TryFrom<(Config, &CodSpeedConfig)> for ExecutionContext {
3939
) -> Result<Self, Self::Error> {
4040
let provider = run_environment::get_provider(&config)?;
4141
let system_info = SystemInfo::new()?;
42-
check_system::check_system(&system_info)?;
42+
system::check_system(&system_info)?;
4343
let logger = Logger::new(provider.as_ref())?;
4444

4545
let profile_folder = if let Some(profile_folder) = &config.profile_folder {

src/executor/helpers/apt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::run_with_sudo::run_with_sudo;
2-
use crate::cli::run::check_system::SystemInfo;
32
use crate::prelude::*;
3+
use crate::system::SystemInfo;
44
use std::path::Path;
55
use std::process::Command;
66

0 commit comments

Comments
 (0)