-
-
Notifications
You must be signed in to change notification settings - Fork 599
/
Copy pathruntime.rs
58 lines (43 loc) · 1.23 KB
/
runtime.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Sonic
//
// Fast, lightweight and schema-less search backend
// Copyright: 2019, Valerian Saliou <[email protected]>
// License: Mozilla Public License v2.0 (MPL v2.0)
use std::thread;
use std::time::{Duration, Instant};
use crate::store::fst::StoreFSTPool;
use crate::store::kv::StoreKVPool;
pub struct TaskerBuilder;
pub struct Tasker;
const TASKER_TICK_INTERVAL: Duration = Duration::from_secs(10);
impl TaskerBuilder {
pub fn new() -> Tasker {
Tasker {}
}
}
impl Tasker {
pub fn run(&self) {
info!("tasker is now active");
loop {
// Hold for next aggregate run
thread::sleep(TASKER_TICK_INTERVAL);
debug!("running a tasker tick...");
let tick_start = Instant::now();
Self::tick();
let tick_took = tick_start.elapsed();
info!(
"ran tasker tick (took {}s + {}ms)",
tick_took.as_secs(),
tick_took.subsec_millis()
);
}
}
fn tick() {
// Proceed all tick actions
// #1: Janitors
StoreKVPool::janitor();
StoreFSTPool::janitor();
// #2: Others
StoreFSTPool::consolidate(false);
}
}