snapshot batch handler

This commit is contained in:
ad hoc 2022-05-23 16:30:06 +02:00
parent 8743d73973
commit 7b47e4e87a
No known key found for this signature in database
GPG key ID: 4F00A782990CC643
6 changed files with 39 additions and 7 deletions

View file

@ -1,3 +1,4 @@
pub mod dump_handler;
pub mod empty_handler;
mod index_resolver_handler;
pub mod snapshot_handler;

View 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) {
()
}
}

View file

@ -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;

View file

@ -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();
}