mirror of
https://github.com/perstarkse/minne.git
synced 2026-04-24 01:38:29 +02:00
working datetime impl
This commit is contained in:
@@ -40,14 +40,7 @@ use zettle_db::{
|
|||||||
},
|
},
|
||||||
AppState,
|
AppState,
|
||||||
},
|
},
|
||||||
storage::{
|
storage::{db::SurrealDbClient, types::user::User},
|
||||||
db::SurrealDbClient,
|
|
||||||
types::{
|
|
||||||
file_info::FileInfo, job::Job, knowledge_entity::KnowledgeEntity,
|
|
||||||
knowledge_relationship::KnowledgeRelationship, text_chunk::TextChunk,
|
|
||||||
text_content::TextContent, user::User,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
utils::{config::get_config, mailer::Mailer},
|
utils::{config::get_config, mailer::Mailer},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use std::{
|
use std::sync::Arc;
|
||||||
sync::Arc,
|
|
||||||
time::{SystemTime, UNIX_EPOCH},
|
|
||||||
};
|
|
||||||
use surrealdb::{opt::PatchOp, Error, Notification};
|
use surrealdb::{opt::PatchOp, Error, Notification};
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
|
|
||||||
@@ -74,17 +71,11 @@ impl JobQueue {
|
|||||||
id: &str,
|
id: &str,
|
||||||
status: JobStatus,
|
status: JobStatus,
|
||||||
) -> Result<Option<Job>, AppError> {
|
) -> Result<Option<Job>, AppError> {
|
||||||
let now = SystemTime::now()
|
|
||||||
.duration_since(UNIX_EPOCH)
|
|
||||||
.unwrap()
|
|
||||||
.as_millis()
|
|
||||||
.to_string();
|
|
||||||
|
|
||||||
let job: Option<Job> = self
|
let job: Option<Job> = self
|
||||||
.db
|
.db
|
||||||
.update((Job::table_name(), id))
|
.update((Job::table_name(), id))
|
||||||
.patch(PatchOp::replace("/status", status))
|
.patch(PatchOp::replace("/status", status))
|
||||||
.patch(PatchOp::replace("/updated_at", now))
|
.patch(PatchOp::replace("/updated_at", Utc::now()))
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(job)
|
Ok(job)
|
||||||
@@ -98,11 +89,9 @@ impl JobQueue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get unfinished jobs, ie newly created and in progress up two times
|
/// Get unfinished jobs, ie newly created and in progress up two times
|
||||||
// pub async fn get_unfinished_jobs(&self) -> Result<Vec<Job>, AppError> {
|
pub async fn get_unfinished_jobs(&self) -> Result<Vec<Job>, AppError> {
|
||||||
pub async fn get_unfinished_jobs(&self) -> Result<(), AppError> {
|
|
||||||
info!("Getting unfinished jobs");
|
info!("Getting unfinished jobs");
|
||||||
// let jobs: Vec<Job> = self
|
let jobs: Vec<Job> = self
|
||||||
let jobs = self
|
|
||||||
.db
|
.db
|
||||||
.query(
|
.query(
|
||||||
"SELECT * FROM type::table($table)
|
"SELECT * FROM type::table($table)
|
||||||
@@ -116,14 +105,10 @@ impl JobQueue {
|
|||||||
)
|
)
|
||||||
.bind(("table", Job::table_name()))
|
.bind(("table", Job::table_name()))
|
||||||
.bind(("max_attempts", MAX_ATTEMPTS))
|
.bind(("max_attempts", MAX_ATTEMPTS))
|
||||||
.await?;
|
.await?
|
||||||
// .take(0)?;
|
.take(0)?;
|
||||||
|
|
||||||
info!("{:?}", jobs);
|
Ok(jobs)
|
||||||
// println!("Unfinished jobs found: {}", jobs.len());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
// Ok(jobs)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to process a single job
|
// Method to process a single job
|
||||||
|
|||||||
@@ -72,45 +72,14 @@ macro_rules! stored_object {
|
|||||||
Into::<surrealdb::sql::Datetime>::into(*date).serialize(serializer)
|
Into::<surrealdb::sql::Datetime>::into(*date).serialize(serializer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn deserialize_datetime<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
|
|
||||||
// where
|
|
||||||
// D: serde::Deserializer<'de>,
|
|
||||||
// {
|
|
||||||
// let dt = surrealdb::sql::Datetime::deserialize(deserializer)?;
|
|
||||||
// Ok(DateTime::<Utc>::from(dt))
|
|
||||||
// }
|
|
||||||
fn deserialize_datetime<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
|
fn deserialize_datetime<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
{
|
{
|
||||||
use serde::de::Error;
|
let dt = surrealdb::sql::Datetime::deserialize(deserializer)?;
|
||||||
|
|
||||||
// Accept various formats
|
|
||||||
let value = serde_json::Value::deserialize(deserializer)?;
|
|
||||||
|
|
||||||
match value {
|
|
||||||
// Handle string format
|
|
||||||
serde_json::Value::String(s) => {
|
|
||||||
if s.starts_with("d\"") && s.ends_with('\"') {
|
|
||||||
let cleaned = &s[2..s.len()-1];
|
|
||||||
DateTime::parse_from_rfc3339(cleaned)
|
|
||||||
.map(|dt| dt.with_timezone(&Utc))
|
|
||||||
.map_err(Error::custom)
|
|
||||||
} else {
|
|
||||||
DateTime::parse_from_rfc3339(&s)
|
|
||||||
.map(|dt| dt.with_timezone(&Utc))
|
|
||||||
.map_err(Error::custom)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// Handle object format (in case SurrealDB returns datetime as an object)
|
|
||||||
serde_json::Value::Object(_) => {
|
|
||||||
let dt = surrealdb::sql::Datetime::deserialize(value)
|
|
||||||
.map_err(Error::custom)?;
|
|
||||||
Ok(DateTime::<Utc>::from(dt))
|
Ok(DateTime::<Utc>::from(dt))
|
||||||
},
|
}
|
||||||
_ => Err(Error::custom("unexpected datetime format")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct $name {
|
pub struct $name {
|
||||||
|
|||||||
Reference in New Issue
Block a user