Skip to content

Commit 957c3e9

Browse files
committed
Wire ContractPreviewStatus through PollRetryPolicy
ContractPreviewStatus's Response changes from Option<PollState> to bool (preview builds never had a target_url to accumulate, so the richer PollState wrapper added nothing). poll() now builds ServiceBuilder::new().retry(PollRetryPolicy::new(...)).service(status) instead of calling the removed poll_preview_build, and maps the one-shot result fetch's error to PreviewResultUnavailable inline instead of via a separate remapping helper.
1 parent 2a22560 commit 957c3e9

2 files changed

Lines changed: 39 additions & 34 deletions

File tree

crates/rover-client/src/operations/contract/preview/mod.rs

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
mod service;
22
mod types;
33

4+
use std::time::Duration;
5+
6+
use rover_tower::poll_retry::PollRetryPolicy;
47
pub use service::{ContractPreviewResult, ContractPreviewStart};
5-
use tower::{Service, ServiceExt};
8+
use tower::{Service, ServiceBuilder, ServiceExt};
69
pub use types::*;
710

8-
use crate::{blocking::StudioClient, shared::preview_poll::poll_preview_build, RoverClientError};
11+
use crate::{blocking::StudioClient, RoverClientError};
912

1013
/// Start an async contract preview job, returning its (pending) status
1114
/// immediately.
@@ -22,20 +25,6 @@ pub async fn start(
2225
service.call(input).await
2326
}
2427

25-
/// Check the status (without fetching the result) of a contract preview build.
26-
async fn status(
27-
input: ContractPreviewStatusInput,
28-
client: &StudioClient,
29-
) -> Result<Option<crate::shared::check_workflow_poll::PollState>, RoverClientError> {
30-
let mut service = service::ContractPreviewStatus::new(
31-
client
32-
.studio_graphql_service()
33-
.map_err(|err| RoverClientError::ServiceReady(Box::new(err)))?,
34-
);
35-
let service = service.ready().await?;
36-
service.call(input).await
37-
}
38-
3928
/// Fetch the full result of a previously started contract preview build.
4029
pub async fn result(
4130
input: ContractPreviewStatusInput,
@@ -50,19 +39,42 @@ pub async fn result(
5039
service.call(input).await
5140
}
5241

53-
/// Continuously poll the status of an already-started contract preview build.
42+
/// Continuously poll the status of an already-started contract preview build,
43+
/// then fetch its full result once it's finished.
5444
pub async fn poll(
5545
status_input: ContractPreviewStatusInput,
5646
client: &StudioClient,
5747
checks_timeout_seconds: u64,
5848
) -> Result<PreviewJobResponse, RoverClientError> {
59-
poll_preview_build(
60-
checks_timeout_seconds,
61-
&status_input.build_id,
62-
async || status(status_input.clone(), client).await,
63-
async || result(status_input.clone(), client).await,
64-
)
65-
.await
49+
let build_id = status_input.build_id.clone();
50+
let mut status_service = ServiceBuilder::new()
51+
.retry(PollRetryPolicy::new(
52+
Duration::from_secs(5),
53+
Duration::from_secs(checks_timeout_seconds),
54+
{
55+
let build_id = build_id.clone();
56+
move || RoverClientError::PreviewTimeoutError {
57+
build_id: build_id.clone(),
58+
}
59+
},
60+
))
61+
.service(service::ContractPreviewStatus::new(
62+
client
63+
.studio_graphql_service()
64+
.map_err(|err| RoverClientError::ServiceReady(Box::new(err)))?,
65+
));
66+
status_service
67+
.ready()
68+
.await?
69+
.call(status_input.clone())
70+
.await?;
71+
72+
result(status_input, client).await.map_err(|source| {
73+
RoverClientError::PreviewResultUnavailable {
74+
build_id,
75+
source: Box::new(source),
76+
}
77+
})
6678
}
6779

6880
/// Start an async contract preview build then poll until it reaches a

crates/rover-client/src/operations/contract/preview/service.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use tower::Service;
66

77
use crate::{
88
operations::contract::preview::types::{ContractPreviewInput, ContractPreviewStatusInput},
9-
shared::{
10-
check_workflow_poll::PollState, preview_poll::require_variant, AsyncBuildStatus,
11-
PreviewJobResponse,
12-
},
9+
shared::{preview_poll::require_variant, AsyncBuildStatus, PreviewJobResponse},
1310
RoverClientError,
1411
};
1512

@@ -131,7 +128,7 @@ where
131128
+ 'static,
132129
Fut: Future<Output = Result<S::Response, S::Error>> + Send,
133130
{
134-
type Response = Option<PollState>;
131+
type Response = bool;
135132
type Error = RoverClientError;
136133
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
137134

@@ -164,11 +161,7 @@ where
164161

165162
use contract_preview_status_query::ContractPreviewStatusQueryGraphVariantContractPreviewStatus as Status;
166163

167-
let finished = !matches!(status, Status::ContractPreviewAsyncPending);
168-
Ok(Some(PollState {
169-
finished,
170-
target_url: None,
171-
}))
164+
Ok(!matches!(status, Status::ContractPreviewAsyncPending))
172165
};
173166
Box::pin(fut)
174167
}

0 commit comments

Comments
 (0)