mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 09:48:44 +00:00
Centralize priority level definitions
This commit is contained in:
1 parent
90c1e1bebf
commit
739363cfe7
6 files changed
+32
-8
No files matched your search
Generated
+1
@@ -4391,6 +4391,7 @@ dependencies = [
|
||||
"tokio 1.13.0",
|
||||
"tokio-tungstenite",
|
||||
"toml",
|
||||
"tts_common",
|
||||
"twitch_api2",
|
||||
"twitch_common",
|
||||
"twitch_oauth2",
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod clean_symbols;
|
||||
pub mod clean_symbols;
|
||||
pub mod priority;
|
||||
@@ -0,0 +1,19 @@
|
||||
/// A centralized accounting of various priority levels, since they would otherwise be strewn
|
||||
/// across various microservices.
|
||||
|
||||
// TODO: Prioritize certain geographic regions? By time of day? Other heuristics?
|
||||
// TODO: Prioritize first few uses? Cooldown on priority?
|
||||
// TODO: Paid priority levels.
|
||||
|
||||
/// Anonymous browser sessions
|
||||
pub const FAKEYOU_ANONYMOUS_PRIORITY_LEVEL : u8 = 0;
|
||||
|
||||
/// Logged in users
|
||||
pub const FAKEYOU_LOGGED_IN_PRIORITY_LEVEL : u8 = 1;
|
||||
|
||||
/// Investors accessing storyteller.io
|
||||
pub const FAKEYOU_INVESTOR_PRIORITY_LEVEL : u8 = 2;
|
||||
|
||||
/// Twitch users get priority above all FakeYou users.
|
||||
/// TODO: In the future, there should be higher priority for paid users.
|
||||
pub const TWITCH_TTS_PRIORITY_LEVEL : u8 = 10;
|
||||
@@ -5,6 +5,7 @@ use actix_web::cookie::Cookie;
|
||||
use actix_web::error::ResponseError;
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::{Responder, web, HttpResponse, error, HttpRequest};
|
||||
use crate::http_server::endpoints::investor_demo::demo_cookie::request_has_demo_cookie;
|
||||
use crate::http_server::web_utils::ip_address::get_request_ip;
|
||||
use crate::http_server::web_utils::response_error_helpers::to_simple_json_error;
|
||||
use crate::server_state::ServerState;
|
||||
@@ -22,8 +23,8 @@ use sqlx::error::Error::Database;
|
||||
use sqlx::mysql::MySqlDatabaseError;
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use tts_common::priority::{FAKEYOU_LOGGED_IN_PRIORITY_LEVEL, FAKEYOU_ANONYMOUS_PRIORITY_LEVEL, FAKEYOU_INVESTOR_PRIORITY_LEVEL};
|
||||
use user_input_common::check_for_slurs::contains_slurs;
|
||||
use crate::http_server::endpoints::investor_demo::demo_cookie::request_has_demo_cookie;
|
||||
|
||||
// TODO: Temporary for investor demo
|
||||
const STORYTELLER_DEMO_COOKIE_NAME : &'static str = "storyteller_demo";
|
||||
@@ -97,7 +98,11 @@ pub async fn infer_tts_handler(
|
||||
// ==================== PRIORITY ==================== //
|
||||
|
||||
// Give logged in users execution priority.
|
||||
let mut priority_level = if maybe_user_session.is_some() { 1 } else { 0 };
|
||||
let mut priority_level = if maybe_user_session.is_some() {
|
||||
FAKEYOU_LOGGED_IN_PRIORITY_LEVEL
|
||||
} else {
|
||||
FAKEYOU_ANONYMOUS_PRIORITY_LEVEL
|
||||
};
|
||||
|
||||
// TODO/TEMP: Give investors even more priority
|
||||
let mut is_investor = false;
|
||||
@@ -118,7 +123,7 @@ pub async fn infer_tts_handler(
|
||||
}
|
||||
|
||||
if is_investor {
|
||||
priority_level = 2;
|
||||
priority_level = FAKEYOU_INVESTOR_PRIORITY_LEVEL;
|
||||
}
|
||||
|
||||
// ==================== RATE LIMIT ==================== //
|
||||
|
||||
@@ -20,6 +20,7 @@ container_common = { path = "../../lib/container_common" }
|
||||
database_queries = { path = "../../lib/database_queries" }
|
||||
http_server_common = { path = "../../lib/http_server_common" }
|
||||
redis_common = { path = "../../lib/redis_common" }
|
||||
tts_common = { path = "../../lib/tts_common" }
|
||||
twitch_common = { path = "../../lib/twitch_common" }
|
||||
|
||||
# External
|
||||
|
||||
+1
-4
@@ -9,13 +9,10 @@ use redis_common::redis_keys::RedisKeys;
|
||||
use redis_common::shared_constants::STREAMER_TTS_JOB_QUEUE_TTL_SECONDS;
|
||||
use sqlx::MySql;
|
||||
use std::sync::Arc;
|
||||
use tts_common::priority::TWITCH_TTS_PRIORITY_LEVEL;
|
||||
use twitch_common::cheers::remove_cheers;
|
||||
use twitch_common::twitch_user_id::TwitchUserId;
|
||||
|
||||
/// Twitch users get priority above all FakeYou users.
|
||||
/// TODO: In the future, there should be higher priority for paid users.
|
||||
const TWITCH_TTS_PRIORITY_LEVEL : u8 = 10;
|
||||
|
||||
pub struct TtsWriter {
|
||||
mysql_pool: Arc<sqlx::Pool<MySql>>,
|
||||
redis_pool: Arc<r2d2::Pool<RedisConnectionManager>>,
|
||||
|
||||
Reference in new issue
Block a user