fix stuff and add warden back
This commit is contained in:
parent
844fa6b54f
commit
1d84cf666f
@ -108,15 +108,15 @@ function createSocket(events) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceJoin(instanceId, constructs) {
|
function sendInstanceJoin(instanceId, constructs) {
|
||||||
send(['Instancejoin', { instance_id: instanceId, construct_ids: constructs }]);
|
send(['InstanceJoin', { instance_id: instanceId, construct_ids: constructs }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceNew(constructs, name, pve) {
|
function sendInstanceNew(constructs, name, pve) {
|
||||||
send(['Instancenew', { construct_ids: constructs, name, pve }]);
|
send(['InstanceLobby', { construct_ids: constructs, name, pve }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceReady(instanceId) {
|
function sendInstanceReady(instanceId) {
|
||||||
send(['instance_ready', { instance_id: instanceId }]);
|
send(['InstanceReady', { instance_id: instanceId }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMtxApply(constructId, mtx) {
|
function sendMtxApply(constructId, mtx) {
|
||||||
|
|||||||
@ -702,6 +702,7 @@ pub fn instance_new(tx: &mut Transaction, account: &Account, construct_ids: Vec<
|
|||||||
let mut instance = match pve {
|
let mut instance = match pve {
|
||||||
true => {
|
true => {
|
||||||
let bot = bot_player();
|
let bot = bot_player();
|
||||||
|
let bot_id = bot.id;
|
||||||
|
|
||||||
// generate bot imgs only in the real world
|
// generate bot imgs only in the real world
|
||||||
for c in bot.constructs.iter() {
|
for c in bot.constructs.iter() {
|
||||||
@ -714,6 +715,7 @@ pub fn instance_new(tx: &mut Transaction, account: &Account, construct_ids: Vec<
|
|||||||
.set_name(name)?;
|
.set_name(name)?;
|
||||||
|
|
||||||
instance.add_player(bot)?;
|
instance.add_player(bot)?;
|
||||||
|
instance.player_ready(bot_id)?;
|
||||||
|
|
||||||
instance
|
instance
|
||||||
},
|
},
|
||||||
|
|||||||
@ -50,9 +50,13 @@ mod vbox;
|
|||||||
mod warden;
|
mod warden;
|
||||||
mod ws;
|
mod ws;
|
||||||
|
|
||||||
use std::thread::spawn;
|
use std::thread::{sleep, spawn};
|
||||||
|
use std::time::{Duration};
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
|
|
||||||
|
use pubsub::pg_listen;
|
||||||
|
use warden::warden;
|
||||||
|
|
||||||
fn setup_logger() -> Result<(), fern::InitError> {
|
fn setup_logger() -> Result<(), fern::InitError> {
|
||||||
fern::Dispatch::new()
|
fern::Dispatch::new()
|
||||||
.format(|out, message, record| {
|
.format(|out, message, record| {
|
||||||
@ -65,7 +69,7 @@ fn setup_logger() -> Result<(), fern::InitError> {
|
|||||||
))
|
))
|
||||||
})
|
})
|
||||||
.level_for("postgres", log::LevelFilter::Info)
|
.level_for("postgres", log::LevelFilter::Info)
|
||||||
.level_for("actix_web", log::LevelFilter::Info)
|
.level_for("iron", log::LevelFilter::Info)
|
||||||
.level(log::LevelFilter::Info)
|
.level(log::LevelFilter::Info)
|
||||||
.chain(std::io::stdout())
|
.chain(std::io::stdout())
|
||||||
.chain(fern::log_file("/var/log/mnml/mnml.log")?)
|
.chain(fern::log_file("/var/log/mnml/mnml.log")?)
|
||||||
@ -81,6 +85,26 @@ fn main() {
|
|||||||
|
|
||||||
let ws_pool = pool.clone();
|
let ws_pool = pool.clone();
|
||||||
let http_pool = pool.clone();
|
let http_pool = pool.clone();
|
||||||
|
let warden_pool = pool.clone();
|
||||||
|
let pubsub_pool = pool.clone();
|
||||||
|
|
||||||
|
spawn(move || {
|
||||||
|
loop {
|
||||||
|
let db_connection = warden_pool.get().expect("unable to get db connection");
|
||||||
|
if let Err(e) = warden(db_connection) {
|
||||||
|
info!("{:?}", e);
|
||||||
|
}
|
||||||
|
sleep(Duration::new(1, 0));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
spawn(move || loop {
|
||||||
|
let pubsub_conn = pubsub_pool.get().expect("could not get pubsub pg connection");
|
||||||
|
match pg_listen(pubsub_conn) {
|
||||||
|
Ok(_) => warn!("pg listen closed"),
|
||||||
|
Err(e) => warn!("pg_listen error {:?}", e),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
spawn(move || net::start(http_pool));
|
spawn(move || net::start(http_pool));
|
||||||
ws::start(ws_pool);
|
ws::start(ws_pool);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user