1use camel_api::function::FunctionId;
2use dashmap::DashMap;
3use std::sync::{Arc, Mutex};
4use tokio_util::sync::CancellationToken;
5
6#[derive(Debug, Clone, Hash, Eq, PartialEq)]
7pub struct RunnerPoolKey {
8 pub runtime: String,
9}
10
11#[derive(Debug, Clone)]
12pub enum RunnerState {
13 Booting,
14 Healthy,
15 Unhealthy {
16 since: std::time::Instant,
17 reason: String,
18 },
19 Failed {
20 reason: String,
21 },
22}
23
24#[derive(Debug, Clone)]
25pub struct RunnerHandle {
26 pub id: String,
27 pub state: Arc<Mutex<RunnerState>>,
28 pub cancel: CancellationToken,
29}
30
31pub struct RunnerPool {
32 pub(crate) handles: DashMap<RunnerPoolKey, RunnerHandle>,
33 pub(crate) ref_counts: DashMap<(FunctionId, Option<String>), u32>,
34 pub(crate) function_to_key: DashMap<(FunctionId, Option<String>), RunnerPoolKey>,
35}
36
37impl RunnerPool {
38 pub fn new() -> Self {
39 Self {
40 handles: DashMap::new(),
41 ref_counts: DashMap::new(),
42 function_to_key: DashMap::new(),
43 }
44 }
45}
46
47impl Default for RunnerPool {
48 fn default() -> Self {
49 Self::new()
50 }
51}