mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
snapshot batch handler
This commit is contained in:
parent
8743d73973
commit
7b47e4e87a
6 changed files with 39 additions and 7 deletions
|
@ -1,3 +1,4 @@
|
|||
pub mod dump_handler;
|
||||
pub mod empty_handler;
|
||||
mod index_resolver_handler;
|
||||
pub mod snapshot_handler;
|
||||
|
|
31
meilisearch-lib/src/tasks/batch_handlers/snapshot_handler.rs
Normal file
31
meilisearch-lib/src/tasks/batch_handlers/snapshot_handler.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use crate::tasks::batch::{Batch, BatchContent};
|
||||
use crate::tasks::BatchHandler;
|
||||
|
||||
pub struct SnapshotHandler;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl BatchHandler for SnapshotHandler {
|
||||
fn accept(&self, batch: &Batch) -> bool {
|
||||
match batch.content {
|
||||
BatchContent::Snapshot(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
async fn process_batch(&self, batch: Batch) -> Batch {
|
||||
match batch.content {
|
||||
BatchContent::Snapshot(job) => {
|
||||
if let Err(e) = job.run().await {
|
||||
log::error!("snapshot error: {e}");
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
Batch::empty()
|
||||
}
|
||||
|
||||
async fn finish(&self, _: &Batch) {
|
||||
()
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
use async_trait::async_trait;
|
||||
|
||||
pub use batch_handlers::empty_handler::EmptyBatchHandler;
|
||||
pub use batch_handlers::snapshot_handler::SnapshotHandler;
|
||||
pub use scheduler::Scheduler;
|
||||
pub use task_store::TaskFilter;
|
||||
|
||||
|
|
|
@ -279,10 +279,6 @@ impl Scheduler {
|
|||
self.tasks.insert(task);
|
||||
}
|
||||
|
||||
pub fn register_snapshot(&mut self, job: SnapshotJob) {
|
||||
self.snapshots.push_back(job);
|
||||
}
|
||||
|
||||
/// Clears the processing list, this method should be called when the processing of a batch is finished.
|
||||
pub fn finish(&mut self) {
|
||||
self.processing = Processing::Nothing;
|
||||
|
@ -340,7 +336,7 @@ impl Scheduler {
|
|||
Ok(tasks)
|
||||
}
|
||||
|
||||
pub async fn schedule_snapshot(&mut self, job: SnapshotJob) {
|
||||
pub fn schedule_snapshot(&mut self, job: SnapshotJob) {
|
||||
self.snapshots.push_back(job);
|
||||
self.notify();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue