Initial version of weather microservice
This commit is contained in:
21
microservices/weather/src/write.rs
Normal file
21
microservices/weather/src/write.rs
Normal file
@@ -0,0 +1,21 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use influxdb::{Client, InfluxDbWriteable};
|
||||
use anyhow::Result;
|
||||
|
||||
#[derive(InfluxDbWriteable)]
|
||||
pub struct WeatherReading {
|
||||
pub time: DateTime<Utc>,
|
||||
pub wind_speed: f32,
|
||||
}
|
||||
|
||||
pub async fn write_weather_data(
|
||||
reading: WeatherReading,
|
||||
base_url: &str,
|
||||
database: &str,
|
||||
token: &str,
|
||||
) -> Result<()> {
|
||||
let client = Client::new(base_url, database).with_token(token);
|
||||
let query = reading.into_query("WeatherReading");
|
||||
client.query(query).await?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user