|
1 | 1 | use console::style; |
2 | | -use tokio::time::{Instant, sleep}; |
3 | 2 |
|
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}; |
11 | 5 | use crate::prelude::*; |
| 6 | +use crate::upload::{UploadResult, poll_run_report}; |
12 | 7 |
|
13 | 8 | #[allow(clippy::borrowed_box)] |
14 | 9 | pub async fn poll_results( |
15 | 10 | api_client: &CodSpeedAPIClient, |
16 | 11 | upload_result: &UploadResult, |
17 | 12 | ) -> 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?; |
51 | 14 |
|
52 | 15 | if !response.run.results.is_empty() { |
53 | 16 | end_group!(); |
|
0 commit comments