add the task to the index db in the register task

This commit is contained in:
Tamo 2022-09-07 00:22:58 +02:00 committed by Clément Renault
parent 2b77d54412
commit c1eda13e64
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
3 changed files with 84 additions and 33 deletions

View file

@ -29,13 +29,20 @@ pub struct Task {
}
impl Task {
/// Persist all the temp files associated with the task.
pub fn persist(&self) -> Result<()> {
self.kind.persist()
}
/// Delete all the files associated with the task.
pub fn remove_data(&self) -> Result<()> {
self.kind.remove_data()
}
/// Return the list of indexes updated by this tasks.
pub fn indexes(&self) -> Option<Vec<&str>> {
self.kind.indexes()
}
}
#[derive(Debug, Serialize, Deserialize)]
@ -98,8 +105,10 @@ impl KindWithContent {
}
pub fn persist(&self) -> Result<()> {
use KindWithContent::*;
match self {
KindWithContent::DocumentAddition {
DocumentAddition {
index_name: _,
content_file: _,
} => {
@ -108,21 +117,23 @@ impl KindWithContent {
Ok(())
}
// There is nothing to persist for all these tasks
KindWithContent::DumpExport { .. }
| KindWithContent::DocumentDeletion { .. }
| KindWithContent::ClearAllDocuments { .. }
| KindWithContent::RenameIndex { .. }
| KindWithContent::CreateIndex { .. }
| KindWithContent::DeleteIndex { .. }
| KindWithContent::SwapIndex { .. }
| KindWithContent::CancelTask { .. }
| KindWithContent::Snapshot => Ok(()),
DumpExport { .. }
| DocumentDeletion { .. }
| ClearAllDocuments { .. }
| RenameIndex { .. }
| CreateIndex { .. }
| DeleteIndex { .. }
| SwapIndex { .. }
| CancelTask { .. }
| Snapshot => Ok(()),
}
}
pub fn remove_data(&self) -> Result<()> {
use KindWithContent::*;
match self {
KindWithContent::DocumentAddition {
DocumentAddition {
index_name: _,
content_file: _,
} => {
@ -131,15 +142,33 @@ impl KindWithContent {
Ok(())
}
// There is no data associated with all these tasks
KindWithContent::DumpExport { .. }
| KindWithContent::DocumentDeletion { .. }
| KindWithContent::ClearAllDocuments { .. }
| KindWithContent::RenameIndex { .. }
| KindWithContent::CreateIndex { .. }
| KindWithContent::DeleteIndex { .. }
| KindWithContent::SwapIndex { .. }
| KindWithContent::CancelTask { .. }
| KindWithContent::Snapshot => Ok(()),
DumpExport { .. }
| DocumentDeletion { .. }
| ClearAllDocuments { .. }
| RenameIndex { .. }
| CreateIndex { .. }
| DeleteIndex { .. }
| SwapIndex { .. }
| CancelTask { .. }
| Snapshot => Ok(()),
}
}
pub fn indexes(&self) -> Option<Vec<&str>> {
use KindWithContent::*;
match self {
DumpExport { .. } | Snapshot | CancelTask { .. } => None,
DocumentAddition { index_name, .. }
| DocumentDeletion { index_name, .. }
| ClearAllDocuments { index_name }
| CreateIndex { index_name, .. }
| DeleteIndex { index_name } => Some(vec![index_name]),
RenameIndex {
index_name: lhs,
new_name: rhs,
}
| SwapIndex { lhs, rhs } => Some(vec![lhs, rhs]),
}
}
}