fix reclaimning
This commit is contained in:
parent
03aae7e3cd
commit
618f366796
@ -110,7 +110,7 @@ function Vbox(args) {
|
||||
if (boundTimer) {
|
||||
clearTimeout(boundTimer);
|
||||
|
||||
if (reclaiming && i) sendVboxReclaim(i);
|
||||
if (reclaiming && vbox.bound[i]) sendVboxReclaim(i);
|
||||
else if (vbox.bound[i]) {
|
||||
const insert = combiner.findIndex(j => j === null);
|
||||
if (insert === -1) return setCombiner([i, null, null]);
|
||||
@ -128,7 +128,7 @@ function Vbox(args) {
|
||||
}
|
||||
|
||||
function boundClick(e, i) {
|
||||
if (reclaiming && i) sendVboxReclaim(i);
|
||||
if (reclaiming && vbox.bound[i]) sendVboxReclaim(i);
|
||||
else if (vbox.bound[i]) {
|
||||
const insert = combiner.findIndex(j => j === null);
|
||||
if (insert === -1) return setCombiner([i, null, null]);
|
||||
@ -210,6 +210,7 @@ function Vbox(args) {
|
||||
return setReclaiming(!reclaiming);
|
||||
}
|
||||
|
||||
console.log('reclaiminig', reclaiming)
|
||||
const classes = `vbox ${activeVar !== null || activeCryp ? 'hidden' : ''}`;
|
||||
const reclaimClass = `instance-btn instance-ui-btn vbox-btn ${reclaiming ? 'reclaiming' : ''}`;
|
||||
|
||||
|
||||
@ -14,8 +14,8 @@ exports.up = async knex => {
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.binary('data').notNullable();
|
||||
table.boolean('open')
|
||||
.defaultTo(true)
|
||||
table.boolean('finished')
|
||||
.defaultTo(false)
|
||||
.notNullable()
|
||||
.index();
|
||||
});
|
||||
|
||||
@ -10,9 +10,10 @@ serde = "1"
|
||||
serde_derive = "1"
|
||||
serde_cbor = "0.9"
|
||||
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
||||
tungstenite = "0.6"
|
||||
bcrypt = "0.2"
|
||||
petgraph = { version = "0.4", features = ["serde-1"] }
|
||||
|
||||
dotenv = "0.9.0"
|
||||
env_logger = "*"
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
use rand::prelude::*;
|
||||
use uuid::Uuid;
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
// Db Commons
|
||||
use serde_cbor::{from_slice, to_vec};
|
||||
use postgres::transaction::Transaction;
|
||||
@ -588,7 +590,7 @@ impl Game {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn handle_afk(mut self) -> Game {
|
||||
pub fn upkeep(mut self) -> Game {
|
||||
self
|
||||
}
|
||||
}
|
||||
@ -703,13 +705,19 @@ pub fn game_get(tx: &mut Transaction, id: Uuid) -> Result<Game, Error> {
|
||||
return Ok(game);
|
||||
}
|
||||
|
||||
pub fn games_afk(tx: &mut Transaction) -> Result<Vec<Game>, Error> {
|
||||
pub fn games_need_upkeep(tx: &mut Transaction) -> Result<Vec<Game>, Error> {
|
||||
// let query = "
|
||||
// SELECT data, id
|
||||
// FROM games
|
||||
// WHERE updated_at < now() - interval '5 seconds'
|
||||
// AND finished = false;
|
||||
// ";
|
||||
|
||||
let query = "
|
||||
SELECT data, id
|
||||
FROM games
|
||||
WHERE updated_at < now() - interval '5 seconds';
|
||||
WHERE finished = false;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
.query(query, &[])?;
|
||||
|
||||
@ -839,13 +847,13 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> {
|
||||
|
||||
let query = "
|
||||
UPDATE games
|
||||
SET data = $1, updated_at = now()
|
||||
WHERE id = $2
|
||||
SET data = $1, complete = $2, updated_at = now()
|
||||
WHERE id = $3
|
||||
RETURNING id, data;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
.query(query, &[&game_bytes, &game.id])?;
|
||||
.query(query, &[&game_bytes, &game.finished(), &game.id])?;
|
||||
|
||||
result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?;
|
||||
|
||||
|
||||
@ -72,7 +72,7 @@ impl Instance {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_afk(mut self) -> Instance {
|
||||
pub fn upkeep(mut self) -> Instance {
|
||||
self
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ pub fn instance_get_open(tx: &mut Transaction) -> Result<Instance, Error> {
|
||||
return Ok(instance);
|
||||
}
|
||||
|
||||
pub fn instances_afk(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
pub fn instances_need_upkeep(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
FROM instances
|
||||
|
||||
@ -3,33 +3,28 @@ extern crate uuid;
|
||||
extern crate tungstenite;
|
||||
extern crate env_logger;
|
||||
extern crate bcrypt;
|
||||
extern crate chrono;
|
||||
|
||||
extern crate dotenv;
|
||||
// extern crate petgraph;
|
||||
extern crate postgres;
|
||||
extern crate r2d2;
|
||||
extern crate r2d2_postgres;
|
||||
|
||||
extern crate serde;
|
||||
extern crate serde_cbor;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[macro_use] extern crate serde_derive;
|
||||
#[macro_use] extern crate failure;
|
||||
// #[macro_use] extern crate failure_derive;
|
||||
|
||||
mod cryp;
|
||||
mod game;
|
||||
mod net;
|
||||
mod skill;
|
||||
mod spec;
|
||||
// mod passives;
|
||||
mod names;
|
||||
mod rpc;
|
||||
mod account;
|
||||
mod instance;
|
||||
mod player;
|
||||
// mod zone;
|
||||
mod mob;
|
||||
mod util;
|
||||
mod vbox;
|
||||
|
||||
@ -9,24 +9,24 @@ use failure::err_msg;
|
||||
use r2d2::{Pool};
|
||||
use r2d2_postgres::{PostgresConnectionManager};
|
||||
|
||||
use game::{Game, games_afk, game_update};
|
||||
use instance::{Instance, instances_afk, instance_update};
|
||||
use game::{Game, games_need_upkeep, game_update};
|
||||
use instance::{Instance, instances_need_upkeep, instance_update};
|
||||
|
||||
fn fetch_games(mut tx: Transaction) -> Result<Transaction, Error> {
|
||||
let games = games_afk(&mut tx)?;
|
||||
let games = games_need_upkeep(&mut tx)?;
|
||||
|
||||
for mut game in games {
|
||||
game_update(&mut tx, &game.handle_afk())?;
|
||||
game_update(&mut tx, &game.upkeep())?;
|
||||
}
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
|
||||
fn fetch_instances(mut tx: Transaction) -> Result<Transaction, Error> {
|
||||
let instances = instances_afk(&mut tx)?;
|
||||
let instances = instances_need_upkeep(&mut tx)?;
|
||||
|
||||
for mut instance in instances {
|
||||
instance_update(&mut tx, instance.handle_afk())?;
|
||||
instance_update(&mut tx, instance.upkeep())?;
|
||||
}
|
||||
|
||||
Ok(tx)
|
||||
@ -42,6 +42,6 @@ pub fn warden(pool: Pool<PostgresConnectionManager>) -> Result<(), Error> {
|
||||
fetch_instances(db_connection.transaction()?)?
|
||||
.commit()?;
|
||||
|
||||
sleep(Duration::new(30, 0));
|
||||
sleep(Duration::new(1, 0));
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user