add the batch_id to the tasks

This commit is contained in:
Tamo 2024-11-13 11:27:12 +01:00
parent 057fcb3993
commit 6062914654
No known key found for this signature in database
GPG key ID: 20CD8020AFA88D69
126 changed files with 755 additions and 158 deletions

View file

@ -0,0 +1,18 @@
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;
pub type BatchId = u32;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Batch {
pub uid: BatchId,
#[serde(with = "time::serde::rfc3339")]
pub started_at: OffsetDateTime,
#[serde(with = "time::serde::rfc3339::option")]
pub finished_at: Option<OffsetDateTime>,
// pub details: Option<Details>,
// pub status: Status,
}

View file

@ -322,6 +322,7 @@ InvalidTaskReverse , InvalidRequest , BAD_REQUEST ;
InvalidTaskStatuses , InvalidRequest , BAD_REQUEST ;
InvalidTaskTypes , InvalidRequest , BAD_REQUEST ;
InvalidTaskUids , InvalidRequest , BAD_REQUEST ;
InvalidBatchUids , InvalidRequest , BAD_REQUEST ;
IoError , System , UNPROCESSABLE_ENTITY;
FeatureNotEnabled , InvalidRequest , BAD_REQUEST ;
MalformedPayload , InvalidRequest , BAD_REQUEST ;

View file

@ -1,3 +1,4 @@
pub mod batches;
pub mod compression;
pub mod deserr;
pub mod document_formats;

View file

@ -2,6 +2,7 @@ use milli::Object;
use serde::Serialize;
use time::{Duration, OffsetDateTime};
use crate::batches::BatchId;
use crate::error::ResponseError;
use crate::settings::{Settings, Unchecked};
use crate::tasks::{serialize_duration, Details, IndexSwap, Kind, Status, Task, TaskId};
@ -10,6 +11,7 @@ use crate::tasks::{serialize_duration, Details, IndexSwap, Kind, Status, Task, T
#[serde(rename_all = "camelCase")]
pub struct TaskView {
pub uid: TaskId,
pub batch_uid: Option<BatchId>,
#[serde(default)]
pub index_uid: Option<String>,
pub status: Status,
@ -33,6 +35,7 @@ impl TaskView {
pub fn from_task(task: &Task) -> TaskView {
TaskView {
uid: task.uid,
batch_uid: task.batch_uid,
index_uid: task.index_uid().map(ToOwned::to_owned),
status: task.status,
kind: task.kind.as_kind(),

View file

@ -11,6 +11,7 @@ use serde::{Deserialize, Serialize, Serializer};
use time::{Duration, OffsetDateTime};
use uuid::Uuid;
use crate::batches::BatchId;
use crate::error::ResponseError;
use crate::keys::Key;
use crate::settings::{Settings, Unchecked};
@ -22,6 +23,7 @@ pub type TaskId = u32;
#[serde(rename_all = "camelCase")]
pub struct Task {
pub uid: TaskId,
pub batch_uid: Option<BatchId>,
#[serde(with = "time::serde::rfc3339")]
pub enqueued_at: OffsetDateTime,
@ -60,6 +62,11 @@ impl Task {
}
}
pub fn with_batch_id(mut self, batch_id: TaskId) -> Self {
self.batch_uid = Some(batch_id);
self
}
/// Return the list of indexes updated by this tasks.
pub fn indexes(&self) -> Vec<&str> {
self.kind.indexes()