Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce supervised indexing #59

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions chaindexing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,32 @@ impl Chaindexing {
) -> Result<(), ChaindexingError> {
config.validate()?;

let mut supervised = Self::start_indexing_in_supervised_mode(config);
let config = config.clone();
tokio::spawn(async move {
let mut interval = time::interval(Duration::from_secs(60));

loop {
interval.tick().await;
if supervised.is_finished() {
supervised = Self::start_indexing_in_supervised_mode(&config);
}
}
});

Ok(())
}
fn start_indexing_in_supervised_mode<S: Send + Sync + Clone + Debug + 'static>(
config: &Config<S>,
) -> task::JoinHandle<()> {
let config = config.clone();
tokio::spawn(async move {
let _ignored_result = Self::start_indexing(&config).await;
})
}
async fn start_indexing<S: Send + Sync + Clone + Debug + 'static>(
config: &Config<S>,
) -> Result<task::JoinHandle<()>, ChaindexingError> {
let Config { repo, .. } = config;
let query_client = repo.get_raw_query_client().await;
let pool = repo.get_pool(1).await;
Expand All @@ -95,7 +121,7 @@ impl Chaindexing {
let mut tasks_are_aborted = false;

let config = config.clone();
tokio::spawn(async move {
let nodes_orchestrator = tokio::spawn(async move {
let mut interval = time::interval(Duration::from_secs(Node::ELECTION_RATE_SECS));

let pool = config.repo.get_pool(1).await;
Expand Down Expand Up @@ -125,7 +151,7 @@ impl Chaindexing {
}
});

Ok(())
Ok(nodes_orchestrator)
}
async fn setup_for_nodes(client: &ChaindexingRepoRawQueryClient) {
ChaindexingRepo::migrate(client, ChaindexingRepo::create_nodes_migration().to_vec()).await;
Expand Down
Loading