mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-29 22:01:59 +02:00
feat: surrealdb queue and remove lapin and rabbitmq
This commit is contained in:
@@ -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)?;
|
||||
|
||||
34
src/server/routes/api/ingress_task.rs
Normal file
34
src/server/routes/api/ingress_task.rs
Normal 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)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod ingress;
|
||||
pub mod ingress_task;
|
||||
pub mod query;
|
||||
pub mod queue_length;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user