use std::path::PathBuf;
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum QueryProgressEvent {
CacheRefresh {
component: String,
path: PathBuf,
source_endpoint: String,
},
PagedRefresh {
progress: PagedQueryProgress,
state: QueryProgressState,
},
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum QueryProgressCollection {
NnsNeurons,
NnsProposals,
SnsNeurons,
IcrcAccountTransactions,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PagedQueryProgress {
pub collection: QueryProgressCollection,
pub target: Option<String>,
pub pages_fetched: u32,
pub rows_fetched: usize,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum QueryProgressState {
Running,
Complete,
Failed,
Stopped,
Stalled,
}
pub trait QueryProgress: Send {
fn report(&mut self, event: QueryProgressEvent);
}
impl<Reporter> QueryProgress for Reporter
where
Reporter: FnMut(QueryProgressEvent) + Send,
{
fn report(&mut self, event: QueryProgressEvent) {
self(event);
}
}
#[cfg(any(
feature = "icrc-host",
feature = "nns-host",
feature = "sns-host",
feature = "subnet-catalog-host",
test
))]
pub struct IgnoreQueryProgress;
#[cfg(any(
feature = "icrc-host",
feature = "nns-host",
feature = "sns-host",
feature = "subnet-catalog-host",
test
))]
impl QueryProgress for IgnoreQueryProgress {
fn report(&mut self, _event: QueryProgressEvent) {}
}