times
This commit is contained in:
parent
59320da37d
commit
abe8a445ae
@ -44,6 +44,7 @@ impl Actor for MnmlSocket {
|
||||
impl StreamHandler<ws::Message, ws::ProtocolError> for MnmlSocket {
|
||||
fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) {
|
||||
// process websocket messages
|
||||
let begin = Instant::now();
|
||||
println!("msg: {:?}", msg);
|
||||
match msg {
|
||||
ws::Message::Ping(msg) => {
|
||||
@ -60,7 +61,7 @@ impl StreamHandler<ws::Message, ws::ProtocolError> for MnmlSocket {
|
||||
ws::Message::Nop => (),
|
||||
ws::Message::Binary(bin) => {
|
||||
let db_connection = self.pool.get().expect("unable to get db connection");
|
||||
match receive(bin.to_vec(), &db_connection, ctx) {
|
||||
match receive(bin.to_vec(), &db_connection, ctx, begin) {
|
||||
Ok(reply) => {
|
||||
let response = to_vec(&reply)
|
||||
.expect("failed to serialize response");
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use std::time::{Instant};
|
||||
|
||||
use actix_web_actors::ws;
|
||||
|
||||
use postgres::transaction::Transaction;
|
||||
use serde_cbor::{from_slice, to_vec};
|
||||
use serde_cbor::{from_slice};
|
||||
use uuid::Uuid;
|
||||
use failure::Error;
|
||||
use failure::err_msg;
|
||||
@ -18,7 +20,7 @@ use item::{Item, ItemInfoCtr, item_info};
|
||||
|
||||
type MnmlWs = ws::WebsocketContext<MnmlSocket>;
|
||||
|
||||
pub fn receive(data: Vec<u8>, db: &Db, client: &mut MnmlWs) -> Result<RpcResponse, Error> {
|
||||
pub fn receive(data: Vec<u8>, db: &Db, client: &mut MnmlWs, begin: Instant) -> Result<RpcResponse, Error> {
|
||||
// cast the data to this type to receive method name
|
||||
match from_slice::<RpcMessage>(&data) {
|
||||
Ok(v) => {
|
||||
@ -87,6 +89,8 @@ pub fn receive(data: Vec<u8>, db: &Db, client: &mut MnmlWs) -> Result<RpcRespons
|
||||
|
||||
tx.commit()?;
|
||||
|
||||
info!("method={:?} account={:?} duration={:?}", v.method, account_name, begin.elapsed());
|
||||
|
||||
return response;
|
||||
},
|
||||
Err(e) => {
|
||||
@ -144,6 +148,8 @@ fn handle_game_ready(data: Vec<u8>, tx: &mut Transaction, account: Account, _cli
|
||||
fn handle_construct_spawn(data: Vec<u8>, tx: &mut Transaction, account: Account, client: &mut MnmlWs) -> Result<RpcResponse, Error> {
|
||||
let msg = from_slice::<ConstructSpawnMsg>(&data).or(Err(err_msg("invalid params")))?;
|
||||
|
||||
construct_spawn(msg.params, tx, &account)?;
|
||||
|
||||
let construct_list = RpcResponse {
|
||||
method: "account_constructs".to_string(),
|
||||
params: RpcResult::ConstructList(account_constructs(tx, &account)?)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user