Skip to main content

ora/admin/
executors.rs

1//! Interface for querying executor information.
2
3use std::time::SystemTime;
4
5use eyre::{Context, OptionExt};
6use tonic::Request;
7
8use crate::{AdminClient, JobTypeId, executor::ExecutorId, proto::admin::v1::ListExecutorsRequest};
9
10/// Information about a registered executor.
11#[derive(Debug)]
12pub struct ExecutorInfo {
13    /// The unique identifier of the executor.
14    pub id: ExecutorId,
15    /// The name of the executor.
16    pub name: Option<String>,
17    /// The time the executor was last seen.
18    pub last_seen_at: SystemTime,
19    /// Queues belonging to the executor.
20    pub queues: Vec<ExecutorQueueInfo>,
21}
22
23/// A job queue belonging to an executor.
24#[derive(Debug)]
25pub struct ExecutorQueueInfo {
26    /// The job type ID of the queue.
27    pub job_type_id: JobTypeId,
28    /// The number of active executions.
29    pub active_executions: u64,
30    /// The maximum number of concurrent executions allowed.
31    pub max_concurrent_executions: u64,
32}
33
34impl AdminClient {
35    /// List connected executors.
36    pub async fn list_executors(&self) -> crate::Result<Vec<ExecutorInfo>> {
37        self.inner
38            .list_executors(Request::new(ListExecutorsRequest {}))
39            .await?
40            .into_inner()
41            .executors
42            .into_iter()
43            .map(|j| {
44                Ok(ExecutorInfo {
45                    id: ExecutorId(j.id.parse().wrap_err("invalid executor ID")?),
46                    name: j.name,
47                    last_seen_at: j
48                        .last_seen_at
49                        .map(TryInto::try_into)
50                        .transpose()
51                        .wrap_err("invalid last_seen_at")?
52                        .ok_or_eyre("missing last_seen_at")?,
53                    queues: j
54                        .queues
55                        .into_iter()
56                        .map(|q| {
57                            Ok(ExecutorQueueInfo {
58                                job_type_id: JobTypeId::new(
59                                    q.job_type.ok_or_eyre("missing job type")?.id,
60                                )?,
61                                active_executions: q.active_executions,
62                                max_concurrent_executions: q.max_concurrent_executions,
63                            })
64                        })
65                        .collect::<Result<Vec<_>, crate::Error>>()?,
66                })
67            })
68            .collect::<Result<Vec<_>, crate::Error>>()
69    }
70}