Skip to content

Commit

Permalink
chore: harmonize event props
Browse files Browse the repository at this point in the history
+ fix typos
  • Loading branch information
frsechet committed Sep 27, 2021
1 parent 962f830 commit 64e0022
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions csml_engine/src/init.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::db_connectors::{conversations::*, memories::*};
use crate::{
data::{ConversationInfo, CsmlRequest, Database, EngineError},
utils::{get_default_flow, get_flow_by_id, search_flow, get_tll_value, get_low_data_value},
utils::{get_default_flow, get_flow_by_id, search_flow, get_ttl_duration_value, get_low_data_mode_value},
Context, CsmlBot, CsmlFlow, CsmlResult,
};

Expand Down Expand Up @@ -42,8 +42,8 @@ pub fn init_conversation_info<'a>(
// let interaction_id = init_interaction(request.payload.clone(), &request.client, &mut db)?;

let mut context = init_context(default_flow, request.client.clone(), &bot.fn_endpoint);
let ttl = get_tll_value(Some(event));
let low_data = get_low_data_value(event);
let ttl = get_ttl_duration_value(Some(event));
let low_data = get_low_data_mode_value(event);

// Do we have a flow matching the request? If the user is requesting a flow in one way
// or another, this takes precedence over any previously open conversation
Expand Down
6 changes: 3 additions & 3 deletions csml_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ pub fn create_client_memory(
init_logger();
validate_memory_key_format(&key)?;

let ttl = get_tll_value(None);
let ttl = get_ttl_duration_value(None);

memories::create_client_memory(client, key, value, ttl, &mut db)
}
Expand Down Expand Up @@ -464,10 +464,10 @@ pub fn get_status() -> Result<serde_json::Value, EngineError> {
}

/**
* delete expired data
* delete expired data
*/
pub fn delete_expired_data() -> Result<(), EngineError> {
let mut db = init_db()?;

clean_db::delete_expired_data(&mut db)
}
}
16 changes: 8 additions & 8 deletions csml_engine/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ pub fn format_event(json_event: serde_json::Value) -> Result<Event, EngineError>
content_type,
content_value,
content,
ttl: json_event["payload"]["tll"].as_i64(),
low_data: json_event["payload"]["tll"].as_bool(),
ttl_duration: json_event["payload"]["ttl_duration"].as_i64(),
low_data_mode: json_event["payload"]["low_data_mode"].as_bool(),
})
}

Expand Down Expand Up @@ -340,10 +340,10 @@ pub fn init_logger() {
};
}

pub fn get_tll_value(event: Option<&Event>) -> Option<chrono::Duration> {
pub fn get_ttl_duration_value(event: Option<&Event>) -> Option<chrono::Duration> {

if let Some(event) = event {
if let Some(ttl) = event.ttl {
if let Some(ttl) = event.ttl_duration {
return Some(chrono::Duration::days(ttl))
}
}
Expand All @@ -357,13 +357,13 @@ pub fn get_tll_value(event: Option<&Event>) -> Option<chrono::Duration> {
return None
}

pub fn get_low_data_value(event: &Event) -> bool {
if let Some(low_data) = event.low_data {
pub fn get_low_data_mode_value(event: &Event) -> bool {
if let Some(low_data) = event.low_data_mode {
return low_data;
}

if let Ok(ttl) = env::var("LOW_DATA_MODE") {
if let Ok(low_data) = ttl.parse::<bool>() {
if let Ok(low_data) = env::var("LOW_DATA_MODE") {
if let Ok(low_data) = low_data.parse::<bool>() {
return low_data;
}
}
Expand Down
4 changes: 2 additions & 2 deletions csml_interpreter/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn main() {
content_type: "payload".to_owned(), // text
content_value: "4".to_owned(),
content: serde_json::json!({"payload":"4"}),
ttl: None,
low_data: None,
ttl_duration: None,
low_data_mode: None,
};

// Create context
Expand Down
12 changes: 6 additions & 6 deletions csml_interpreter/src/data/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub struct Event {
pub content_type: String,
pub content_value: String,
pub content: serde_json::Value,
pub ttl: Option<i64>,
pub low_data: Option<bool>,
pub ttl_duration: Option<i64>,
pub low_data_mode: Option<bool>,
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -21,8 +21,8 @@ impl Default for Event {
content_type: String::default(),
content_value: String::default(),
content: serde_json::json!({}),
ttl: None,
low_data: None,
ttl_duration: None,
low_data_mode: None,
}
}
}
Expand All @@ -37,8 +37,8 @@ impl Event {
content_type: content_type.to_owned(),
content_value: content_value.to_owned(),
content,
ttl: None,
low_data: None,
ttl_duration: None,
low_data_mode: None,
}
}
}

0 comments on commit 64e0022

Please sign in to comment.