mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-03 17:08:13 +00:00
starting to add new redis pubsub to websocket gateway
This commit is contained in:
1 parent
6e682b8afe
commit
dfa3cd3074
3 files changed
+27
-11
No files matched your search
@@ -104,17 +104,13 @@ pub async fn main() -> AnyhowResult<()> {
|
|||||||
.enable_all()
|
.enable_all()
|
||||||
.build()?;
|
.build()?;
|
||||||
|
|
||||||
let runtime = Arc::new(runtime);
|
|
||||||
|
|
||||||
// https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html
|
// https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html
|
||||||
let runtime_2 = Builder::new_multi_thread()
|
let runtime_2 = Arc::new(Builder::new_multi_thread()
|
||||||
.worker_threads(8)
|
.worker_threads(8)
|
||||||
.thread_name("twitch-pubsub-")
|
.thread_name("twitch-pubsub-")
|
||||||
.thread_stack_size(3 * 1024 * 1024)
|
.thread_stack_size(3 * 1024 * 1024)
|
||||||
.enable_all()
|
.enable_all()
|
||||||
.build()?;
|
.build()?);
|
||||||
|
|
||||||
let runtime_2 = Arc::new(runtime_2);
|
|
||||||
|
|
||||||
info!("Thread pool created");
|
info!("Thread pool created");
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ use config::shared_constants::DEFAULT_REDIS_DATABASE_1_CONNECTION_STRING;
|
|||||||
use config::shared_constants::DEFAULT_RUST_LOG;
|
use config::shared_constants::DEFAULT_RUST_LOG;
|
||||||
use container_common::anyhow_result::AnyhowResult;
|
use container_common::anyhow_result::AnyhowResult;
|
||||||
use crate::endpoints_ws::obs_gateway_websocket_handler::obs_gateway_websocket_handler;
|
use crate::endpoints_ws::obs_gateway_websocket_handler::obs_gateway_websocket_handler;
|
||||||
use crate::server_state::{ObsGatewayServerState, EnvConfig, TwitchOauthSecrets, BackendsConfig};
|
use crate::server_state::{ObsGatewayServerState, EnvConfig, TwitchOauthSecrets, BackendsConfig, MultithreadingConfig};
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
use futures::executor::ThreadPool;
|
use futures::executor::ThreadPool;
|
||||||
use http_server_common::cors::build_common_cors_config;
|
use http_server_common::cors::build_common_cors_config;
|
||||||
@@ -40,7 +40,7 @@ use sqlx::mysql::MySqlPoolOptions;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tokio::runtime::{Handle, Runtime};
|
use tokio::runtime::{Builder, Handle, Runtime};
|
||||||
use twitch_api2::pubsub::Topic;
|
use twitch_api2::pubsub::Topic;
|
||||||
use twitch_api2::pubsub;
|
use twitch_api2::pubsub;
|
||||||
use twitch_common::twitch_secrets::TwitchSecrets;
|
use twitch_common::twitch_secrets::TwitchSecrets;
|
||||||
@@ -106,7 +106,15 @@ async fn main() -> AnyhowResult<()> {
|
|||||||
let redis_pool = r2d2::Pool::builder()
|
let redis_pool = r2d2::Pool::builder()
|
||||||
.build(redis_manager)?;
|
.build(redis_manager)?;
|
||||||
|
|
||||||
|
let runtime = Arc::new(Builder::new_multi_thread()
|
||||||
|
.worker_threads(32)
|
||||||
|
.thread_name("redis-pubsub-event-consumer-")
|
||||||
|
.thread_stack_size(3 * 1024 * 1024)
|
||||||
|
.enable_all()
|
||||||
|
.build()?);
|
||||||
|
|
||||||
let server_state = ObsGatewayServerState {
|
let server_state = ObsGatewayServerState {
|
||||||
|
hostname: server_hostname,
|
||||||
env_config: EnvConfig {
|
env_config: EnvConfig {
|
||||||
num_workers,
|
num_workers,
|
||||||
bind_address,
|
bind_address,
|
||||||
@@ -119,11 +127,13 @@ async fn main() -> AnyhowResult<()> {
|
|||||||
client_id: twitch_secrets.app_client_id.clone(),
|
client_id: twitch_secrets.app_client_id.clone(),
|
||||||
client_secret: twitch_secrets.app_client_secret.clone(),
|
client_secret: twitch_secrets.app_client_secret.clone(),
|
||||||
},
|
},
|
||||||
hostname: server_hostname,
|
|
||||||
backends: BackendsConfig {
|
backends: BackendsConfig {
|
||||||
mysql_pool: pool,
|
mysql_pool: pool,
|
||||||
redis_pool,
|
redis_pool,
|
||||||
}
|
},
|
||||||
|
multithreading: MultithreadingConfig {
|
||||||
|
redis_pubsub_runtime: runtime,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
info!("Starting server...");
|
info!("Starting server...");
|
||||||
|
|||||||
@@ -1,18 +1,23 @@
|
|||||||
use r2d2_redis::{r2d2, RedisConnectionManager};
|
use r2d2_redis::{r2d2, RedisConnectionManager};
|
||||||
use sqlx::MySqlPool;
|
use sqlx::MySqlPool;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
use twitch_oauth2::{ClientId, ClientSecret};
|
use twitch_oauth2::{ClientId, ClientSecret};
|
||||||
|
|
||||||
/// State that is injected into every endpoint.
|
/// State that is injected into every endpoint.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct ObsGatewayServerState {
|
pub struct ObsGatewayServerState {
|
||||||
|
pub hostname: String,
|
||||||
|
|
||||||
/// Configuration from ENV vars.
|
/// Configuration from ENV vars.
|
||||||
/// Some of this might not be used.
|
/// Some of this might not be used.
|
||||||
pub env_config: EnvConfig,
|
pub env_config: EnvConfig,
|
||||||
pub hostname: String,
|
|
||||||
|
|
||||||
pub twitch_oauth_secrets: TwitchOauthSecrets,
|
pub twitch_oauth_secrets: TwitchOauthSecrets,
|
||||||
|
|
||||||
pub backends: BackendsConfig,
|
pub backends: BackendsConfig,
|
||||||
|
|
||||||
|
pub multithreading: MultithreadingConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -39,3 +44,8 @@ pub struct TwitchOauthSecrets {
|
|||||||
pub client_id: String,
|
pub client_id: String,
|
||||||
pub client_secret: String,
|
pub client_secret: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct MultithreadingConfig {
|
||||||
|
pub redis_pubsub_runtime: Arc<Runtime>,
|
||||||
|
}
|
||||||
Reference in new issue
Block a user