Deploy Poimen Memory K8s cluster with ArgoCD tracking (M2.2, M3.5-M3.7)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
/// Ingest request.
|
||||
#[derive(Deserialize, Clone)]
|
||||
pub struct IngestRequest {
|
||||
pub project: String,
|
||||
pub source: String,
|
||||
pub ingest_id: String,
|
||||
}
|
||||
|
||||
/// Job status.
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct JobStatus {
|
||||
pub job_id: String,
|
||||
pub ingest_id: String,
|
||||
pub project: String,
|
||||
pub status: String,
|
||||
pub chunks_seen: u32,
|
||||
pub chunks_used: u32,
|
||||
}
|
||||
|
||||
/// In-memory ingest queue.
|
||||
pub struct IngestQueue {
|
||||
jobs: BTreeMap<String, JobStatus>,
|
||||
}
|
||||
|
||||
impl IngestQueue {
|
||||
/// Create new queue.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
jobs: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Submit job (idempotent by ingest_id).
|
||||
pub fn submit(&mut self, project: &str, ingest_id: &str) -> (String, bool) {
|
||||
if let Some(existing) = self.jobs.get(ingest_id) {
|
||||
(existing.job_id.clone(), false)
|
||||
} else {
|
||||
let job_id = format!("ingest-{}", Uuid::new_v4());
|
||||
self.jobs.insert(
|
||||
ingest_id.to_string(),
|
||||
JobStatus {
|
||||
job_id: job_id.clone(),
|
||||
ingest_id: ingest_id.to_string(),
|
||||
project: project.to_string(),
|
||||
status: "queued".to_string(),
|
||||
chunks_seen: 0,
|
||||
chunks_used: 0,
|
||||
},
|
||||
);
|
||||
(job_id, true)
|
||||
}
|
||||
}
|
||||
|
||||
/// Get job status by job_id.
|
||||
pub fn get_status(&self, job_id: &str) -> Option<JobStatus> {
|
||||
self.jobs.values().find(|j| j.job_id == job_id).cloned()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user