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