working datetime impl

This commit is contained in:
Per Stark
2025-01-13 22:10:41 +01:00
parent bdb23bd3af
commit 560249e5ae
3 changed files with 14 additions and 67 deletions

View File

@@ -1,9 +1,6 @@
use chrono::Utc;
use futures::Stream;
use std::{
sync::Arc,
time::{SystemTime, UNIX_EPOCH},
};
use std::sync::Arc;
use surrealdb::{opt::PatchOp, Error, Notification};
use tracing::{error, info};
@@ -74,17 +71,11 @@ impl JobQueue {
id: &str,
status: JobStatus,
) -> Result<Option<Job>, AppError> {
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis()
.to_string();
let job: Option<Job> = self
.db
.update((Job::table_name(), id))
.patch(PatchOp::replace("/status", status))
.patch(PatchOp::replace("/updated_at", now))
.patch(PatchOp::replace("/updated_at", Utc::now()))
.await?;
Ok(job)
@@ -98,11 +89,9 @@ impl JobQueue {
}
/// 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<(), AppError> {
pub async fn get_unfinished_jobs(&self) -> Result<Vec<Job>, AppError> {
info!("Getting unfinished jobs");
// let jobs: Vec<Job> = self
let jobs = self
let jobs: Vec<Job> = self
.db
.query(
"SELECT * FROM type::table($table)
@@ -116,14 +105,10 @@ impl JobQueue {
)
.bind(("table", Job::table_name()))
.bind(("max_attempts", MAX_ATTEMPTS))
.await?;
// .take(0)?;
.await?
.take(0)?;
info!("{:?}", jobs);
// println!("Unfinished jobs found: {}", jobs.len());
Ok(())
// Ok(jobs)
Ok(jobs)
}
// Method to process a single job