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
pub mod scheduling {
extern crate async_std;
extern crate clokwerk;
extern crate influxdb;
extern crate log;
use async_std::task::block_on;
use clokwerk::{Interval, Scheduler};
use influxdb::{Client, InfluxDbWriteable};
use log::info;
pub fn schedule_writable<F, G>(client: Client, measurement: &'static str, interval: Interval, f: F)
where
F: Fn() -> G + Sync + 'static + Send,
G: InfluxDbWriteable + Send,
{
let client: Client = client.clone();
let mut scheduler: Scheduler = Scheduler::new();
scheduler.every(interval).run(move || {
block_on(async {
let query = f().into_query(measurement);
client.query(&query).await.unwrap();
info!("Successfully wrote to DB");
})
});
loop {
scheduler.run_pending()
}
}
}