fix: include server epoch in start_bas_executed key to invalidate after restart
All checks were successful
BotServer CI / build (push) Successful in 17m16s
All checks were successful
BotServer CI / build (push) Successful in 17m16s
This commit is contained in:
parent
492530ee77
commit
ed2a1d83f0
1 changed files with 14 additions and 2 deletions
|
|
@ -39,11 +39,23 @@ use log::{error, info, warn};
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::OnceLock;
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tokio::sync::Mutex as AsyncMutex;
|
use tokio::sync::Mutex as AsyncMutex;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
static SERVER_START_EPOCH: OnceLock<u64> = OnceLock::new();
|
||||||
|
|
||||||
|
fn server_epoch() -> u64 {
|
||||||
|
*SERVER_START_EPOCH.get_or_init(|| {
|
||||||
|
std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.map(|d| d.as_secs())
|
||||||
|
.unwrap_or(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
pub mod channels;
|
pub mod channels;
|
||||||
pub mod multimedia;
|
pub mod multimedia;
|
||||||
|
|
||||||
|
|
@ -546,7 +558,7 @@ impl BotOrchestrator {
|
||||||
let actual_session_id = session.id.to_string();
|
let actual_session_id = session.id.to_string();
|
||||||
|
|
||||||
// Check if start.bas has already been executed for this session
|
// Check if start.bas has already been executed for this session
|
||||||
let start_bas_key = format!("start_bas_executed:{}", actual_session_id);
|
let start_bas_key = format!("start_bas_executed:{}:{}", server_epoch(), actual_session_id);
|
||||||
let should_execute_start_bas = if let Some(cache) = &self.state.cache {
|
let should_execute_start_bas = if let Some(cache) = &self.state.cache {
|
||||||
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
||||||
let executed: Result<Option<String>, redis::RedisError> = redis::cmd("GET")
|
let executed: Result<Option<String>, redis::RedisError> = redis::cmd("GET")
|
||||||
|
|
@ -1330,7 +1342,7 @@ async fn handle_websocket(
|
||||||
|
|
||||||
if let Some(bot_name) = bot_name_result {
|
if let Some(bot_name) = bot_name_result {
|
||||||
// Check if start.bas has already been executed for this session
|
// Check if start.bas has already been executed for this session
|
||||||
let start_bas_key = format!("start_bas_executed:{}", session_id);
|
let start_bas_key = format!("start_bas_executed:{}:{}", server_epoch(), session_id);
|
||||||
let should_execute_start_bas = if let Some(cache) = &state.cache {
|
let should_execute_start_bas = if let Some(cache) = &state.cache {
|
||||||
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
if let Ok(mut conn) = cache.get_multiplexed_async_connection().await {
|
||||||
let executed: Result<Option<String>, redis::RedisError> = redis::cmd("GET")
|
let executed: Result<Option<String>, redis::RedisError> = redis::cmd("GET")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue