2021-12-02 23:03:26 +08:00
|
|
|
use async_trait::async_trait;
|
2022-01-19 18:21:19 +08:00
|
|
|
|
2022-05-25 14:46:06 +08:00
|
|
|
pub use handlers::empty_handler::EmptyBatchHandler;
|
|
|
|
pub use handlers::snapshot_handler::SnapshotHandler;
|
2022-01-19 18:21:19 +08:00
|
|
|
pub use scheduler::Scheduler;
|
|
|
|
pub use task_store::TaskFilter;
|
2021-12-02 23:03:26 +08:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub use task_store::test::MockTaskStore as TaskStore;
|
|
|
|
#[cfg(not(test))]
|
|
|
|
pub use task_store::TaskStore;
|
|
|
|
|
|
|
|
use batch::Batch;
|
|
|
|
use error::Result;
|
2022-01-19 18:21:19 +08:00
|
|
|
|
2021-12-02 23:03:26 +08:00
|
|
|
pub mod batch;
|
|
|
|
pub mod error;
|
2022-05-25 14:46:06 +08:00
|
|
|
mod handlers;
|
2022-01-19 18:21:19 +08:00
|
|
|
mod scheduler;
|
2021-12-02 23:03:26 +08:00
|
|
|
pub mod task;
|
|
|
|
mod task_store;
|
2022-01-19 18:21:19 +08:00
|
|
|
pub mod update_loop;
|
2021-12-02 23:03:26 +08:00
|
|
|
|
|
|
|
#[cfg_attr(test, mockall::automock(type Error=test::DebugError;))]
|
|
|
|
#[async_trait]
|
2022-05-19 18:43:46 +08:00
|
|
|
pub trait BatchHandler: Sync + Send + 'static {
|
|
|
|
/// return whether this handler can accept this batch
|
|
|
|
fn accept(&self, batch: &Batch) -> bool;
|
|
|
|
|
2021-12-02 23:03:26 +08:00
|
|
|
/// Processes the `Task` batch returning the batch with the `Task` updated.
|
2022-01-19 18:21:19 +08:00
|
|
|
async fn process_batch(&self, batch: Batch) -> Batch;
|
|
|
|
|
2021-12-02 23:03:26 +08:00
|
|
|
/// `finish` is called when the result of `process` has been commited to the task store. This
|
|
|
|
/// method can be used to perform cleanup after the update has been completed for example.
|
|
|
|
async fn finish(&self, batch: &Batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::fmt::Display;
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
pub struct DebugError;
|
|
|
|
|
|
|
|
impl Display for DebugError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_str("an error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for DebugError {}
|
|
|
|
}
|