Explicitely start async executor

This commit is contained in:
Antoine Gersant 2020-01-16 00:41:26 -08:00
parent 1c84cde158
commit 289827d6a3
2 changed files with 21 additions and 17 deletions

View file

@ -217,18 +217,20 @@ fn main() -> Result<()> {
.unwrap_or_else(|| "5050".to_owned())
.parse()
.with_context(|| "Invalid port number")?;
service::server::run(
port,
Some(auth_secret.as_slice()),
api_url,
web_url,
web_dir_path,
swagger_url,
swagger_dir_path,
db.clone(),
command_sender,
)?;
let db_server = db.clone();
std::thread::spawn(move || {
let _ = service::server::run(
port,
Some(auth_secret.as_slice()),
api_url,
web_url,
web_dir_path,
swagger_url,
swagger_dir_path,
db_server,
command_sender,
);
});
// Start DDNS updates
let db_ddns = db.clone();

View file

@ -1,3 +1,4 @@
use actix_rt::System;
use actix_web::{App, HttpServer};
use anyhow::*;
use std::path::PathBuf;
@ -6,8 +7,7 @@ use std::sync::Arc;
use crate::db::DB;
use crate::index::CommandSender;
#[actix_rt::main]
pub async fn run(
pub fn run(
port: u16,
auth_secret: Option<&[u8]>,
api_url: String,
@ -18,7 +18,9 @@ pub async fn run(
db: DB,
command_sender: Arc<CommandSender>,
) -> Result<()> {
HttpServer::new(move || {
let mut sys = System::new("polaris_service_executor");
let server = HttpServer::new(move || {
App::new().configure(|cfg| {
super::configure_app(
cfg,
@ -30,8 +32,8 @@ pub async fn run(
)
})
})
.bind(format!("127.0.0.1:{}", port))?
.bind(format!("0.0.0.0:{}", port))?
.run();
Ok(())
sys.block_on(server).map_err(Error::new)
}