You've already forked AstralRinth
forked from didirus/AstralRinth
* feat(indexing): Reindex curseforge & local database at an interval * fix(indexing): Use strings for meilisearch primary key Fixes #17 by prefixing curseforge ids with "curse-" and local ids with "local-". * feat(indexing): Add newly created mods to the index more quickly * feat(indexing): Implement faceted search, update to meilisearch master Fixes #9, but only uses faceted search for categories. It should be reasonably simple to add support for versions, but it may not be as useful due to the large number of versions and the large number of supported versions for each mod. * feat(indexing): Allow skipping initial indexing Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
31 lines
642 B
Rust
31 lines
642 B
Rust
use actix_rt::time;
|
|
use actix_rt::Arbiter;
|
|
use futures::StreamExt;
|
|
|
|
pub struct Scheduler {
|
|
arbiter: Arbiter,
|
|
}
|
|
|
|
impl Scheduler {
|
|
pub fn new() -> Self {
|
|
Scheduler {
|
|
arbiter: Arbiter::new(),
|
|
}
|
|
}
|
|
|
|
pub fn run<F, R>(&mut self, interval: std::time::Duration, task: F)
|
|
where
|
|
F: Fn() -> R + Send + 'static,
|
|
R: std::future::Future<Output = ()> + Send + 'static,
|
|
{
|
|
let future = time::interval(interval).for_each_concurrent(2, move |_| task());
|
|
self.arbiter.send(future);
|
|
}
|
|
}
|
|
|
|
impl Drop for Scheduler {
|
|
fn drop(&mut self) {
|
|
self.arbiter.stop();
|
|
}
|
|
}
|