diff --git a/Cargo.lock b/Cargo.lock index 0a5ef3e12d..73ed2fd52e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4391,6 +4391,7 @@ dependencies = [ "tokio 1.13.0", "tokio-tungstenite", "toml", + "tts_common", "twitch_api2", "twitch_common", "twitch_oauth2", diff --git a/crates/lib/tts_common/src/lib.rs b/crates/lib/tts_common/src/lib.rs index 82df584c77..84d5f048b5 100644 --- a/crates/lib/tts_common/src/lib.rs +++ b/crates/lib/tts_common/src/lib.rs @@ -1 +1,2 @@ -pub mod clean_symbols; \ No newline at end of file +pub mod clean_symbols; +pub mod priority; \ No newline at end of file diff --git a/crates/lib/tts_common/src/priority.rs b/crates/lib/tts_common/src/priority.rs new file mode 100644 index 0000000000..c5fed96a47 --- /dev/null +++ b/crates/lib/tts_common/src/priority.rs @@ -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; diff --git a/crates/service/storyteller_web/src/http_server/endpoints/tts/enqueue_infer_tts.rs b/crates/service/storyteller_web/src/http_server/endpoints/tts/enqueue_infer_tts.rs index c68791dc24..b140c2250c 100644 --- a/crates/service/storyteller_web/src/http_server/endpoints/tts/enqueue_infer_tts.rs +++ b/crates/service/storyteller_web/src/http_server/endpoints/tts/enqueue_infer_tts.rs @@ -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 ==================== // diff --git a/crates/service/twitch_pubsub_subscriber/Cargo.toml b/crates/service/twitch_pubsub_subscriber/Cargo.toml index c9c752bdfc..8e154cf384 100644 --- a/crates/service/twitch_pubsub_subscriber/Cargo.toml +++ b/crates/service/twitch_pubsub_subscriber/Cargo.toml @@ -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 diff --git a/crates/service/twitch_pubsub_subscriber/src/threads/twitch_pubsub_user_subscriber/tts_writer.rs b/crates/service/twitch_pubsub_subscriber/src/threads/twitch_pubsub_user_subscriber/tts_writer.rs index d6409e1fff..164b78fc24 100644 --- a/crates/service/twitch_pubsub_subscriber/src/threads/twitch_pubsub_user_subscriber/tts_writer.rs +++ b/crates/service/twitch_pubsub_subscriber/src/threads/twitch_pubsub_user_subscriber/tts_writer.rs @@ -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>, redis_pool: Arc>,