WIP refactor channel config usage

This commit is contained in:
Dominik Werder
2023-06-19 10:04:56 +02:00
parent 44dd43240b
commit 0daa66a800
12 changed files with 303 additions and 269 deletions
-50
View File
@@ -1,50 +0,0 @@
use crate::errconv::ErrConv;
use err::Error;
use futures_util::StreamExt;
use netpod::log::*;
use netpod::ChannelConfigQuery;
use netpod::ChannelConfigResponse;
use netpod::ScalarType;
use netpod::SfDbChannel;
use netpod::Shape;
use scylla::Session as ScySession;
use std::sync::Arc;
// TODO unused, table in postgres.
pub async fn config_from_scylla(chq: ChannelConfigQuery, scy: Arc<ScySession>) -> Result<ChannelConfigResponse, Error> {
let cql = "select series, scalar_type, shape_dims from series_by_channel where facility = ? and channel_name = ?";
let mut it = scy
.query_iter(cql, (chq.channel.backend(), chq.channel.name()))
.await
.err_conv()?;
let mut rows = Vec::new();
while let Some(row) = it.next().await {
let row = row.err_conv()?;
let cols = row.into_typed::<(i64, i32, Vec<i32>)>().err_conv()?;
let scalar_type = ScalarType::from_scylla_i32(cols.1)?;
let shape = Shape::from_scylla_shape_dims(&cols.2)?;
let channel = SfDbChannel::from_full(chq.channel.backend(), Some(cols.0 as _), chq.channel.name());
let res = ChannelConfigResponse {
channel,
scalar_type,
byte_order: None,
shape,
};
info!("config_from_scylla: {res:?}");
rows.push(res);
}
if rows.is_empty() {
return Err(Error::with_public_msg_no_trace(format!(
"can not find config for channel {:?}",
chq.channel
)));
} else {
if rows.len() > 1 {
error!(
"Found multiple configurations for channel {:?} {:?}",
chq.channel, rows
);
}
Ok(rows.pop().unwrap())
}
}
-1
View File
@@ -1,5 +1,4 @@
pub mod bincache;
pub mod config;
pub mod errconv;
pub mod events;
pub mod status;