diff options
| author | Jokler <jokler@protonmail.com> | 2020-01-30 15:55:41 +0100 |
|---|---|---|
| committer | Jokler <jokler@protonmail.com> | 2020-02-22 23:20:10 +0100 |
| commit | 757edd214f841e8d95e4c5430d7ead7a0e8fecbb (patch) | |
| tree | 3d0721d1d1f73c9bc1fd5ac23aef505e1051d5e5 /src/main.rs | |
| parent | 2792ba9c8a7120a91b3bd2c6075e737690e73405 (diff) | |
| download | pokebot-757edd214f841e8d95e4c5430d7ead7a0e8fecbb.tar.gz pokebot-757edd214f841e8d95e4c5430d7ead7a0e8fecbb.zip | |
Spawn actix-web server with access to the bot
Additionally replace all Mutexes with RwLocks.
Hopefully this makes it possible for the web server to
serve many requests at once since they would just hold read locks.
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 922162f..2559a2a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ use std::fs::File; use std::io::{Read, Write}; use std::path::PathBuf; +use std::thread; use futures::future::{FutureExt, TryFutureExt}; -use log::{debug, info}; +use log::{debug, error, info}; use structopt::clap::AppSettings; use structopt::StructOpt; use tsclientlib::Identity; @@ -13,6 +14,7 @@ mod bot; mod command; mod playlist; mod teamspeak; +mod web_server; mod youtube_dl; use bot::{MasterArgs, MasterBot, MusicBot, MusicBotArgs}; @@ -116,7 +118,22 @@ fn run() -> Result<(), Box<dyn std::error::Error>> { }; MusicBot::new(bot_args).await.1.await; } else { - MasterBot::new(bot_args).await.1.await; + let domain = bot_args.domain.clone(); + let bind_address = bot_args.bind_address.clone(); + let (bot, fut) = MasterBot::new(bot_args).await; + + thread::spawn(|| { + let web_args = web_server::WebServerArgs { + domain, + bind_address, + bot, + }; + if let Err(e) = web_server::start(web_args) { + error!("Error in web server: {}", e); + } + }); + + fut.await; } } .unit_error() |
