Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add connection timeout to API #419

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/lib/src/qpu/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@ pub struct ExecutionOptions {
#[doc = "The timeout to use for the request, defaults to 30 seconds. If set to `None`, then there is no timeout."]
#[builder(default = "Some(Duration::from_secs(30))")]
timeout: Option<Duration>,
#[doc = "The timeout to use for the connection, defaults to `None`seconds. If set to `None`, then there is no timeout."]
#[builder(default = "Some(Duration::from_secs(30))")]
connection_timeout: Option<Duration>,
#[doc = "Options avaialable when executing a job on a QPU, particular to the execution service's API."]
#[builder(default = "None")]
api_options: Option<InnerApiExecutionOptions>,
Expand Down Expand Up @@ -278,7 +281,11 @@ impl ExecutionOptions {
pub fn timeout(&self) -> Option<Duration> {
self.timeout
}

/// Get the connection timeout.
#[must_use]
pub fn connection_timeout(&self) -> Option<Duration> {
self.connection_timeout
}
/// Get the [`ApiExecutionOptions`].
#[must_use]
pub fn api_options(&self) -> Option<&InnerApiExecutionOptions> {
Expand Down Expand Up @@ -381,7 +388,7 @@ impl ExecutionOptions {
client: &Qcs,
) -> Result<GrpcConnection, QpuApiError> {
let uri = parse_uri(address).map_err(QpuApiError::GrpcError)?;
let channel = get_channel_with_timeout(uri, self.timeout())
let channel = get_channel_with_timeout(uri, self.timeout(), self.connection_timeout())
.map_err(|err| QpuApiError::GrpcError(err.into()))?;
Ok(wrap_channel_with(channel, client.get_config().clone()))
}
Expand Down