Track start time in clients
This commit is contained in:
parent
a6571a51c1
commit
c71b2dbf22
5 changed files with 50 additions and 10 deletions
|
|
@ -6,6 +6,7 @@ edition = { workspace = true }
|
|||
[dependencies]
|
||||
cookie = { workspace = true }
|
||||
euphoxide = { workspace = true }
|
||||
jiff = { workspace = true }
|
||||
log = { workspace = true }
|
||||
tokio = { workspace = true, features = ["rt"] }
|
||||
tokio-tungstenite = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use euphoxide::{
|
|||
api::ParsedPacket,
|
||||
client::{conn::ClientConnHandle, state::State},
|
||||
};
|
||||
use jiff::Timestamp;
|
||||
use tokio::{
|
||||
select,
|
||||
sync::{mpsc, oneshot},
|
||||
|
|
@ -160,6 +161,7 @@ impl MultiClientTask {
|
|||
pub struct MultiClient {
|
||||
config: Arc<MultiClientConfig>,
|
||||
cmd_tx: mpsc::Sender<Command>,
|
||||
start_time: Timestamp,
|
||||
}
|
||||
|
||||
impl MultiClient {
|
||||
|
|
@ -171,6 +173,8 @@ impl MultiClient {
|
|||
config: MultiClientConfig,
|
||||
event_tx: mpsc::Sender<MultiClientEvent>,
|
||||
) -> Self {
|
||||
let start_time = Timestamp::now();
|
||||
|
||||
let config = Arc::new(config);
|
||||
let out_tx = event_tx;
|
||||
|
||||
|
|
@ -188,7 +192,15 @@ impl MultiClient {
|
|||
|
||||
tokio::task::spawn(task.run());
|
||||
|
||||
Self { config, cmd_tx }
|
||||
Self {
|
||||
config,
|
||||
cmd_tx,
|
||||
start_time,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_time(&self) -> Timestamp {
|
||||
self.start_time
|
||||
}
|
||||
|
||||
pub async fn get_clients(&self) -> Vec<Client> {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use euphoxide::{
|
|||
state::State,
|
||||
},
|
||||
};
|
||||
use jiff::Timestamp;
|
||||
use log::warn;
|
||||
use tokio::{
|
||||
select,
|
||||
|
|
@ -337,6 +338,7 @@ impl ClientTask {
|
|||
pub struct Client {
|
||||
id: usize,
|
||||
cmd_tx: mpsc::Sender<Command>,
|
||||
start_time: Timestamp,
|
||||
}
|
||||
|
||||
impl fmt::Debug for Client {
|
||||
|
|
@ -349,6 +351,8 @@ impl fmt::Debug for Client {
|
|||
|
||||
impl Client {
|
||||
pub fn new(id: usize, config: ClientConfig, event_tx: mpsc::Sender<ClientEvent>) -> Self {
|
||||
let start_time = Timestamp::now();
|
||||
|
||||
let (cmd_tx, cmd_rx) = mpsc::channel(config.server.cmd_channel_bufsize);
|
||||
|
||||
let task = ClientTask {
|
||||
|
|
@ -362,13 +366,21 @@ impl Client {
|
|||
|
||||
tokio::task::spawn(task.run());
|
||||
|
||||
Self { id, cmd_tx }
|
||||
Self {
|
||||
id,
|
||||
cmd_tx,
|
||||
start_time,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn id(&self) -> usize {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn start_time(&self) -> Timestamp {
|
||||
self.start_time
|
||||
}
|
||||
|
||||
pub fn stopped(&self) -> bool {
|
||||
self.cmd_tx.is_closed()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue