feat: surrealdb queue and remove lapin and rabbitmq

This commit is contained in:
Per Stark
2025-01-09 21:13:42 +01:00
parent a87cb82b75
commit 0f8a83429a
28 changed files with 622 additions and 1306 deletions

View File

@@ -44,7 +44,7 @@ pub async fn ingress_data(
let futures: Vec<_> = ingress_objects
.into_iter()
.map(|object| state.rabbitmq_producer.publish(object))
.map(|object| state.job_queue.enqueue(object.clone(), user.id.clone()))
.collect();
try_join_all(futures).await.map_err(AppError::from)?;

View File

@@ -0,0 +1,34 @@
use crate::{error::ApiError, server::AppState, storage::types::user::User};
use axum::{
extract::{Path, State},
http::StatusCode,
response::IntoResponse,
Extension, Json,
};
pub async fn get_queue_tasks(
State(state): State<AppState>,
Extension(user): Extension<User>,
) -> Result<impl IntoResponse, ApiError> {
let user_tasks = state
.job_queue
.get_user_jobs(&user.id)
.await
.map_err(ApiError::from)?;
Ok(Json(user_tasks))
}
pub async fn delete_queue_task(
State(state): State<AppState>,
Extension(user): Extension<User>,
Path(id): Path<String>,
) -> Result<impl IntoResponse, ApiError> {
state
.job_queue
.delete_job(&id, &user.id)
.await
.map_err(ApiError::from)?;
Ok(StatusCode::OK)
}

View File

@@ -1,3 +1,4 @@
pub mod ingress;
pub mod ingress_task;
pub mod query;
pub mod queue_length;

View File

@@ -4,6 +4,7 @@ use tracing::info;
use crate::{
error::{ApiError, AppError},
server::AppState,
storage::{db::get_all_stored_items, types::job::Job},
};
pub async fn queue_length_handler(
@@ -11,11 +12,10 @@ pub async fn queue_length_handler(
) -> Result<impl IntoResponse, ApiError> {
info!("Getting queue length");
let queue_length = state
.rabbitmq_consumer
.get_queue_length()
let queue_length = get_all_stored_items::<Job>(&state.surreal_db_client)
.await
.map_err(AppError::from)?;
.map_err(AppError::from)?
.len();
info!("Queue length: {}", queue_length);