Skip to content

Commit 93c9271

Browse files
feat: remove projects query from the exec polling
1 parent 14748da commit 93c9271

9 files changed

Lines changed: 36 additions & 77 deletions

File tree

src/api_client.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,6 @@ pub struct FetchLocalRunReportVars {
8686
pub run_id: String,
8787
}
8888

89-
#[derive(Serialize, Clone)]
90-
#[serde(rename_all = "camelCase")]
91-
pub struct FetchLocalExecReportVars {
92-
pub name: String,
93-
pub run_id: String,
94-
}
9589
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
9690
pub enum ReportConclusion {
9791
AcknowledgedFailure,
@@ -181,10 +175,6 @@ pub struct FetchLocalRunReportResponse {
181175
pub run: FetchLocalRunReportRun,
182176
}
183177

184-
pub struct FetchLocalExecReportResponse {
185-
pub run: FetchLocalRunReportRun,
186-
}
187-
188178
#[derive(Serialize, Clone)]
189179
#[serde(rename_all = "camelCase")]
190180
pub struct GetOrCreateProjectRepositoryVars {
@@ -257,28 +247,6 @@ impl CodSpeedAPIClient {
257247
}
258248
}
259249

260-
pub async fn fetch_local_exec_report(
261-
&self,
262-
vars: FetchLocalExecReportVars,
263-
) -> Result<FetchLocalExecReportResponse> {
264-
let response = self
265-
.gql_client
266-
.query_with_vars_unwrap::<FetchLocalExecReportData, FetchLocalExecReportVars>(
267-
include_str!("queries/FetchLocalExecReport.gql"),
268-
vars.clone(),
269-
)
270-
.await;
271-
match response {
272-
Ok(response) => Ok(FetchLocalExecReportResponse {
273-
run: response.project.run,
274-
}),
275-
Err(err) if err.contains_error_code("UNAUTHENTICATED") => {
276-
bail!("Your session has expired, please login again using `codspeed auth login`")
277-
}
278-
Err(err) => bail!("Failed to fetch local run report: {err}"),
279-
}
280-
}
281-
282250
pub async fn get_or_create_project_repository(
283251
&self,
284252
vars: GetOrCreateProjectRepositoryVars,

src/exec/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::api_client::CodSpeedAPIClient;
22
use crate::config::CodSpeedConfig;
33
use crate::executor;
44
use crate::prelude::*;
5+
use crate::run::uploader::UploadResult;
56
use clap::Args;
67
use std::path::Path;
78

@@ -36,7 +37,10 @@ pub async fn run(
3637
executor::ExecutorCommand::Exec,
3738
);
3839

39-
let poll_results_fn = |run_id: String| poll_results::poll_results(api_client, run_id);
40+
let poll_results_fn = |upload_result: &UploadResult| {
41+
let upload_result = upload_result.clone();
42+
async move { poll_results::poll_results(api_client, &upload_result).await }
43+
};
4044

4145
executor::execute_benchmarks(
4246
executor.as_ref(),

src/exec/poll_results.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ use console::style;
22
use tokio::time::{Instant, sleep};
33

44
use crate::api_client::{
5-
CodSpeedAPIClient, FetchLocalExecReportResponse, FetchLocalExecReportVars, RunStatus,
5+
CodSpeedAPIClient, FetchLocalRunReportResponse, FetchLocalRunReportVars, RunStatus,
66
};
7-
use crate::exec::DEFAULT_REPOSITORY_NAME;
7+
use crate::run::uploader::UploadResult;
88
use crate::prelude::*;
99
use crate::run::helpers::poll_results::{
1010
POLLING_INTERVAL, RUN_PROCESSING_MAX_DURATION, build_benchmark_table,
1111
};
1212

1313
#[allow(clippy::borrowed_box)]
14-
pub async fn poll_results(api_client: &CodSpeedAPIClient, run_id: String) -> Result<()> {
14+
pub async fn poll_results(
15+
api_client: &CodSpeedAPIClient,
16+
upload_result: &UploadResult,
17+
) -> Result<()> {
1518
let start = Instant::now();
16-
let fetch_local_exec_report_vars = FetchLocalExecReportVars {
17-
// TODO: Set this dynamically based on the upload endpoint return value
18-
name: DEFAULT_REPOSITORY_NAME.to_owned(),
19-
run_id: run_id.clone(),
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(),
2023
};
2124

2225
start_group!("Fetching the results");
@@ -27,11 +30,11 @@ pub async fn poll_results(api_client: &CodSpeedAPIClient, run_id: String) -> Res
2730
}
2831

2932
let fetch_result = api_client
30-
.fetch_local_exec_report(fetch_local_exec_report_vars.clone())
33+
.fetch_local_run_report(fetch_local_run_report_vars.clone())
3134
.await?;
3235

3336
match fetch_result {
34-
FetchLocalExecReportResponse { run, .. }
37+
FetchLocalRunReportResponse { run, .. }
3538
if run.status == RunStatus::Pending || run.status == RunStatus::Processing =>
3639
{
3740
sleep(POLLING_INTERVAL).await;

src/executor/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod wall_time;
1414
use crate::instruments::mongo_tracer::{MongoTracer, install_mongodb_tracer};
1515
use crate::prelude::*;
1616
use crate::run::check_system::SystemInfo;
17+
use crate::run::uploader::UploadResult;
1718
use crate::runner_mode::RunnerMode;
1819
use async_trait::async_trait;
1920
pub use config::Config;
@@ -102,7 +103,7 @@ pub async fn execute_benchmarks<F>(
102103
api_client: &crate::api_client::CodSpeedAPIClient,
103104
) -> Result<()>
104105
where
105-
F: AsyncFn(String) -> Result<()>,
106+
F: AsyncFn(&UploadResult) -> Result<()>,
106107
{
107108
if !execution_context.config.skip_setup {
108109
start_group!("Preparing the environment");
@@ -165,7 +166,7 @@ where
165166
end_group!();
166167

167168
if execution_context.is_local() {
168-
poll_results(upload_result.run_id).await?;
169+
poll_results(&upload_result).await?;
169170
}
170171
} else {
171172
debug!("Skipping upload of performance data");

src/queries/FetchLocalExecReport.gql

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

src/run/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::config::CodSpeedConfig;
44
use crate::executor;
55
use crate::executor::Config;
66
use crate::prelude::*;
7+
use crate::run::uploader::UploadResult;
78
use crate::run_environment::interfaces::RepositoryProvider;
89
use crate::runner_mode::RunnerMode;
910
use clap::{Args, ValueEnum};
@@ -201,9 +202,9 @@ pub async fn run(
201202
executor::ExecutorCommand::Run,
202203
);
203204

204-
let run_environment_metadata = execution_context.provider.get_run_environment_metadata()?;
205-
let poll_results_fn = |run_id: String| {
206-
poll_results::poll_results(api_client, &run_environment_metadata, run_id, output_json)
205+
let poll_results_fn = |upload_result: &UploadResult| {
206+
let upload_result = upload_result.clone();
207+
async move { poll_results::poll_results(api_client, &upload_result, output_json).await }
207208
};
208209
executor::execute_benchmarks(
209210
executor.as_ref(),

src/run/poll_results.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@ use crate::prelude::*;
88
use crate::run::helpers::poll_results::{
99
POLLING_INTERVAL, RUN_PROCESSING_MAX_DURATION, build_benchmark_table,
1010
};
11-
use crate::run_environment::RunEnvironmentMetadata;
11+
use crate::run::uploader::UploadResult;
1212

1313
#[allow(clippy::borrowed_box)]
1414
pub async fn poll_results(
1515
api_client: &CodSpeedAPIClient,
16-
run_environment_metadata: &RunEnvironmentMetadata,
17-
run_id: String,
16+
upload_result: &UploadResult,
1817
output_json: bool,
1918
) -> Result<()> {
2019
let start = Instant::now();
21-
let owner = run_environment_metadata.owner.as_str();
22-
let name = run_environment_metadata.repository.as_str();
2320
let fetch_local_run_report_vars = FetchLocalRunReportVars {
24-
owner: owner.to_owned(),
25-
name: name.to_owned(),
26-
run_id: run_id.to_owned(),
21+
owner: upload_result.owner.clone(),
22+
name: upload_result.repository.clone(),
23+
run_id: upload_result.run_id.clone(),
2724
};
2825

2926
start_group!("Fetching the results");
@@ -88,7 +85,7 @@ pub async fn poll_results(
8885
// We could make use of structured logging for this https://docs.rs/log/latest/log/#structured-logging
8986
log_json!(format!(
9087
"{{\"event\": \"run_finished\", \"run_id\": \"{}\"}}",
91-
run_id
88+
upload_result.run_id
9289
));
9390
}
9491

src/run/uploader/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ mod upload_metadata;
55

66
pub use interfaces::*;
77
pub use profile_archive::ProfileArchive;
8-
pub use upload::upload;
8+
pub use upload::{UploadResult, upload};

src/run/uploader/upload.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ async fn upload_profile_archive(
235235
Ok(())
236236
}
237237

238+
#[derive(Clone)]
238239
pub struct UploadResult {
239240
pub run_id: String,
241+
pub owner: String,
242+
pub repository: String,
240243
}
241244

242245
pub async fn upload(
@@ -299,6 +302,8 @@ pub async fn upload(
299302

300303
Ok(UploadResult {
301304
run_id: upload_data.run_id,
305+
owner: upload_metadata.run_environment_metadata.owner.clone(),
306+
repository: upload_metadata.run_environment_metadata.repository.clone(),
302307
})
303308
}
304309

0 commit comments

Comments
 (0)