Tweak tokio worker pool, only start with main server

This commit is contained in:
timvisee 2021-11-11 12:08:10 +01:00
parent 2c5a76f92a
commit 2f3ea381b8
No known key found for this signature in database
GPG Key ID: B8DB720BC383E172
3 changed files with 12 additions and 8 deletions

View File

@ -12,7 +12,7 @@ use crate::service;
const RCON_PASSWORD_LENGTH: usize = 32; const RCON_PASSWORD_LENGTH: usize = 32;
/// Start lazymc. /// Start lazymc.
pub async fn invoke(matches: &ArgMatches) -> Result<(), ()> { pub fn invoke(matches: &ArgMatches) -> Result<(), ()> {
// Load config // Load config
#[allow(unused_mut)] #[allow(unused_mut)]
let mut config = config::load(matches); let mut config = config::load(matches);
@ -27,7 +27,7 @@ pub async fn invoke(matches: &ArgMatches) -> Result<(), ()> {
// Start server service // Start server service
// TODO: start tokio runtime here? // TODO: start tokio runtime here?
let config = Arc::new(config); let config = Arc::new(config);
service::server::service(config).await service::server::service(config)
} }
/// Prepare RCON. /// Prepare RCON.

View File

@ -29,14 +29,13 @@ use clap::App;
const LOG_DEFAULT: &str = "info"; const LOG_DEFAULT: &str = "info";
/// Main entrypoint. /// Main entrypoint.
#[tokio::main] fn main() -> Result<(), ()> {
async fn main() -> Result<(), ()> {
// Initialize logger // Initialize logger
init_log(); init_log();
// Build clap app, invoke intended action // Build clap app, invoke intended action
let app = cli::app(); let app = cli::app();
invoke_action(app).await invoke_action(app)
} }
/// Initialize logger. /// Initialize logger.
@ -54,7 +53,7 @@ fn init_log() {
} }
/// Invoke an action. /// Invoke an action.
async fn invoke_action<'a>(app: App<'a>) -> Result<(), ()> { fn invoke_action<'a>(app: App<'a>) -> Result<(), ()> {
let matches = app.get_matches(); let matches = app.get_matches();
// Config operations // Config operations
@ -69,9 +68,9 @@ async fn invoke_action<'a>(app: App<'a>) -> Result<(), ()> {
return Ok(()); return Ok(());
} }
unimplemented!("Config logic here!"); unreachable!();
} }
// Start server // Start server
action::start::invoke(&matches).await action::start::invoke(&matches)
} }

View File

@ -13,6 +13,11 @@ use crate::status;
use crate::util::error::{quit_error, ErrorHints}; use crate::util::error::{quit_error, ErrorHints};
/// Start lazymc. /// Start lazymc.
///
/// Main entrypoint to start all server/status/proxy logic.
///
/// Spawns a tokio runtime to complete all work on.
#[tokio::main(flavor = "multi_thread")]
pub async fn service(config: Arc<Config>) -> Result<(), ()> { pub async fn service(config: Arc<Config>) -> Result<(), ()> {
// Load server state // Load server state
let server = Arc::new(Server::default()); let server = Arc::new(Server::default());