empty equip

This commit is contained in:
ntr
2019-05-21 11:32:44 +10:00
parent 2c532aa7d1
commit 246489c342
4 changed files with 34 additions and 26 deletions
+16 -23
View File
@@ -9,8 +9,6 @@ use serde_cbor::{to_vec};
use std::env;
use std::thread::{spawn, sleep};
use std::time::{Instant, Duration};
use std::any::Any;
use std::panic;
use r2d2::{Pool};
use r2d2::{PooledConnection};
@@ -35,8 +33,8 @@ struct RpcErrorResponse {
err: String
}
fn receive(db: Db, rpc: &Rpc, msg: Message, client: &mut WebSocket<TcpStream>) -> Result<String, Error> {
match rpc.receive(msg, &db, client) {
fn receive(db: Db, begin: Instant, rpc: &Rpc, msg: Message, client: &mut WebSocket<TcpStream>) -> Result<String, Error> {
match rpc.receive(msg, begin, &db, client) {
Ok(reply) => {
let response = to_vec(&reply)
.expect("failed to serialize response");
@@ -62,18 +60,18 @@ pub fn db_connection(url: String) -> Pool<PostgresConnectionManager> {
.expect("Failed to create pool.")
}
fn print_panic_payload(ctx: &str, payload: &(Any + Send + 'static)) {
let d = format!("{:?}", payload);
let s = if let Some(s) = payload.downcast_ref::<String>() {
&s
} else if let Some(s) = payload.downcast_ref::<&str>() {
s
} else {
// "PAYLOAD IS NOT A STRING"
d.as_str()
};
info!("{}: PANIC OCCURRED: {}", ctx, s);
}
// fn print_panic_payload(ctx: &str, payload: &(Any + Send + 'static)) {
// let d = format!("{:?}", payload);
// let s = if let Some(s) = payload.downcast_ref::<String>() {
// &s
// } else if let Some(s) = payload.downcast_ref::<&str>() {
// s
// } else {
// // "PAYLOAD IS NOT A STRING"
// d.as_str()
// };
// info!("{}: PANIC OCCURRED: {}", ctx, s);
// }
pub fn start() {
// panic::set_hook(Box::new(|panic_info| {
@@ -120,13 +118,8 @@ pub fn start() {
Ok(msg) => {
let begin = Instant::now();
let db_connection = db.get().expect("unable to get db connection");
match receive(db_connection, &rpc, msg, &mut websocket) {
Ok(method) => {
match method.as_ref() {
"pong" => (),
_ => info!("response sent. total duration: {:?}", begin.elapsed()),
}
},
match receive(db_connection, begin, &rpc, msg, &mut websocket) {
Ok(_) => (),
Err(e) => warn!("{:?}", e),
}
},
+4 -3
View File
@@ -6,6 +6,7 @@ use std::net::{TcpStream};
// demo
use std::iter;
use std::time::Instant;
use rand::{thread_rng, Rng};
use rand::distributions::{Alphanumeric};
@@ -28,7 +29,7 @@ use item::{Item, ItemInfoCtr, item_info};
pub struct Rpc;
impl Rpc {
pub fn receive(&self, msg: Message, db: &Db, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
pub fn receive(&self, msg: Message, begin: Instant, db: &Db, client: &mut WebSocket<TcpStream>) -> Result<RpcResponse, Error> {
// consume the ws data into bytes
let data = msg.into_data();
@@ -51,8 +52,6 @@ impl Rpc {
None => "none".to_string(),
};
info!("method={:?} account={:?}", v.method, account_name);
// check the method
// if no auth required
match v.method.as_ref() {
@@ -104,6 +103,8 @@ impl Rpc {
tx.commit()?;
info!("method={:?} account={:?} duration={:?}", v.method, account_name, begin.elapsed());
return response;
},
Err(e) => {