mirror of
https://github.com/perstarkse/minne.git
synced 2026-03-24 02:11:30 +01:00
refactored queue into Job
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use common::{ingress::jobqueue::JobQueue, storage::db::SurrealDbClient, utils::config::AppConfig};
|
||||
use common::{storage::db::SurrealDbClient, utils::config::AppConfig};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApiState {
|
||||
pub surreal_db_client: Arc<SurrealDbClient>,
|
||||
pub job_queue: Arc<JobQueue>,
|
||||
pub db: Arc<SurrealDbClient>,
|
||||
}
|
||||
|
||||
impl ApiState {
|
||||
@@ -24,8 +23,7 @@ impl ApiState {
|
||||
surreal_db_client.ensure_initialized().await?;
|
||||
|
||||
let app_state = ApiState {
|
||||
surreal_db_client: surreal_db_client.clone(),
|
||||
job_queue: Arc::new(JobQueue::new(surreal_db_client)),
|
||||
db: surreal_db_client.clone(),
|
||||
};
|
||||
|
||||
Ok(app_state)
|
||||
|
||||
@@ -17,7 +17,7 @@ pub async fn api_auth(
|
||||
"You have to be authenticated".to_string(),
|
||||
))?;
|
||||
|
||||
let user = User::find_by_api_key(&api_key, &state.surreal_db_client).await?;
|
||||
let user = User::find_by_api_key(&api_key, &state.db).await?;
|
||||
let user = user.ok_or(ApiError::Unauthorized(
|
||||
"You have to be authenticated".to_string(),
|
||||
))?;
|
||||
|
||||
@@ -3,7 +3,7 @@ use axum_typed_multipart::{FieldData, TryFromMultipart, TypedMultipart};
|
||||
use common::{
|
||||
error::{ApiError, AppError},
|
||||
ingress::ingress_input::{create_ingress_objects, IngressInput},
|
||||
storage::types::{file_info::FileInfo, user::User},
|
||||
storage::types::{file_info::FileInfo, job::Job, user::User},
|
||||
};
|
||||
use futures::{future::try_join_all, TryFutureExt};
|
||||
use tempfile::NamedTempFile;
|
||||
@@ -28,9 +28,12 @@ pub async fn ingress_data(
|
||||
) -> Result<impl IntoResponse, ApiError> {
|
||||
info!("Received input: {:?}", input);
|
||||
|
||||
let file_infos = try_join_all(input.files.into_iter().map(|file| {
|
||||
FileInfo::new(file, &state.surreal_db_client, &user.id).map_err(AppError::from)
|
||||
}))
|
||||
let file_infos = try_join_all(
|
||||
input
|
||||
.files
|
||||
.into_iter()
|
||||
.map(|file| FileInfo::new(file, &state.db, &user.id).map_err(AppError::from)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
debug!("Got file infos");
|
||||
@@ -48,7 +51,7 @@ pub async fn ingress_data(
|
||||
|
||||
let futures: Vec<_> = ingress_objects
|
||||
.into_iter()
|
||||
.map(|object| state.job_queue.enqueue(object.clone(), user.id.clone()))
|
||||
.map(|object| Job::create_and_add_to_db(object.clone(), user.id.clone(), &state.db))
|
||||
.collect();
|
||||
|
||||
try_join_all(futures).await.map_err(AppError::from)?;
|
||||
|
||||
Reference in New Issue
Block a user