pub struct ArmadaClient { /* private fields */ }Expand description
Armada gRPC client providing job submission and event-stream watching.
§Construction
Use ArmadaClient::connect for plaintext (dev / in-cluster) connections
and ArmadaClient::connect_tls for production clusters behind TLS.
Both accept any TokenProvider — pass crate::StaticTokenProvider for
a static bearer token or supply your own implementation for dynamic auth.
// Plaintext
let client = ArmadaClient::connect("http://localhost:50051", StaticTokenProvider::new("tok"))
.await?;
// TLS (uses system root certificates)
let client = ArmadaClient::connect_tls("https://armada.example.com:443", StaticTokenProvider::new("tok"))
.await?;§Cloning
ArmadaClient is Clone. All clones share the same underlying channel and
connection pool — cloning is O(1) and is the correct way to distribute the
client across tasks:
let client = ArmadaClient::connect("http://localhost:50051", StaticTokenProvider::new("tok"))
.await?;
let c1 = client.clone();
let c2 = client.clone();
tokio::spawn(async move { /* use c1 */ });
tokio::spawn(async move { /* use c2 */ });§Timeouts
Apply a per-call deadline with ArmadaClient::with_timeout. When set,
every RPC is governed by the deadline for its entire duration. For
unary calls (submit) the deadline covers the round-trip. For streaming
calls (watch) it covers the full lifetime of the stream — if the timeout
elapses while events are still being received the stream is cancelled with
a DEADLINE_EXCEEDED status.
Implementations§
Source§impl ArmadaClient
impl ArmadaClient
Sourcepub async fn connect(
endpoint: impl Into<String>,
token_provider: impl TokenProvider + 'static,
) -> Result<Self, Error>
pub async fn connect( endpoint: impl Into<String>, token_provider: impl TokenProvider + 'static, ) -> Result<Self, Error>
Connect to an Armada server at endpoint using plaintext (no TLS).
endpoint must be a valid URI, e.g. "http://localhost:50051".
§Errors
Returns Error::InvalidUri if the URI is malformed, or
Error::Transport if the connection cannot be established.
Sourcepub async fn connect_tls(
endpoint: impl Into<String>,
token_provider: impl TokenProvider + 'static,
) -> Result<Self, Error>
pub async fn connect_tls( endpoint: impl Into<String>, token_provider: impl TokenProvider + 'static, ) -> Result<Self, Error>
Connect to an Armada server at endpoint using TLS.
Uses the system’s native root certificates to verify the server
certificate. endpoint should use the https:// scheme,
e.g. "https://armada.example.com:443".
§Errors
Returns Error::InvalidUri if the URI is malformed, or
Error::Transport if TLS configuration or the connection fails.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set a default timeout applied to every RPC call.
When the timeout elapses the call fails with Error::Grpc wrapping a
DEADLINE_EXCEEDED status. For streaming calls like
ArmadaClient::watch, the deadline covers the entire stream
duration — if it elapses while events are still arriving the stream
is cancelled immediately.
Returns self so the call can be chained directly after construction:
let client = ArmadaClient::connect("http://localhost:50051", StaticTokenProvider::new("tok"))
.await?
.with_timeout(Duration::from_secs(30));Sourcepub async fn submit(
&self,
request: JobSubmitRequest,
) -> Result<JobSubmitResponse, Error>
pub async fn submit( &self, request: JobSubmitRequest, ) -> Result<JobSubmitResponse, Error>
Submit a batch of jobs to Armada.
Attaches an authorization header on every call using the configured
TokenProvider (e.g. Bearer <token> or Basic <credentials>). Multiple job items can be included in
a single request — they are all submitted atomically to the same queue
and job set.
§Example
use armada_client::{
ArmadaClient, JobRequestItemBuilder, JobSubmitRequest, StaticTokenProvider,
};
use armada_client::k8s::io::api::core::v1::PodSpec;
let item = JobRequestItemBuilder::new()
.namespace("default")
.pod_spec(PodSpec { containers: vec![], ..Default::default() })
.build();
let response = client
.submit(JobSubmitRequest {
queue: "my-queue".into(),
job_set_id: "my-job-set".into(),
job_request_items: vec![item],
})
.await?;
for r in &response.job_response_items {
if r.error.is_empty() {
println!("submitted: {}", r.job_id);
} else {
eprintln!("rejected: {}", r.error);
}
}§Errors
Error::Authif the token provider fails.Error::InvalidMetadataif the token contains invalid header characters.Error::Grpcif the server returns a non-OK status.
Sourcepub async fn watch(
&self,
queue: impl Into<String>,
job_set_id: impl Into<String>,
from_message_id: Option<String>,
) -> Result<BoxStream<'static, Result<EventStreamMessage, Error>>, Error>
pub async fn watch( &self, queue: impl Into<String>, job_set_id: impl Into<String>, from_message_id: Option<String>, ) -> Result<BoxStream<'static, Result<EventStreamMessage, Error>>, Error>
Watch a job set, returning a stream of events.
Opens a server-streaming gRPC call and returns a BoxStream that
yields EventStreamMessage values as the server pushes them. The
stream ends when the server closes the connection.
Reconnection is the caller’s responsibility. Store the last
message_id you received and pass it back as from_message_id when
reconnecting to avoid replaying events you have already processed.
§Arguments
queue— Armada queue name.job_set_id— Job set to watch.from_message_id— Optional resume cursor. PassSome(id)to receive only events that occurred afterid; passNoneto receive all events from the beginning.
§Example
use futures::StreamExt;
use armada_client::{ArmadaClient, StaticTokenProvider};
let mut stream = client
.watch("my-queue", "my-job-set", None)
.await?;
let mut last_id = String::new();
while let Some(result) = stream.next().await {
match result {
Ok(msg) => {
last_id = msg.id.clone();
println!("event id={} message={:?}", msg.id, msg.message);
}
Err(e) => {
eprintln!("stream error: {e}");
break; // reconnect using `from_message_id: Some(last_id)`
}
}
}§Errors
Error::Authif the token provider fails.Error::InvalidMetadataif the token contains invalid header characters.Error::Grpcif the server returns a non-OK status on the initial call. The stream will not error simply because the job set does not exist yet — it will wait for events, which avoids races whenwatchis called immediately aftersubmit.- Individual stream items may also be [
Err(Error::Grpc)] if the server sends a trailing error status.
Trait Implementations§
Source§impl Clone for ArmadaClient
impl Clone for ArmadaClient
Source§fn clone(&self) -> ArmadaClient
fn clone(&self) -> ArmadaClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !Freeze for ArmadaClient
impl !RefUnwindSafe for ArmadaClient
impl Send for ArmadaClient
impl Sync for ArmadaClient
impl Unpin for ArmadaClient
impl UnsafeUnpin for ArmadaClient
impl !UnwindSafe for ArmadaClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request